api

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2023 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	*echo.Echo
	DB db.NodDB

	C Config
	// contains filtered or unexported fields
}

API is the main struct for the API. can be used for both Admin and Query APIs

func NewAPI

func NewAPI(config Config, db db.NodDB) *API

NewAPI creates a new API instance. It won't start till ListenAndServe is called

func (*API) AddAdminPaths

func (api *API) AddAdminPaths()

AddAdminPaths adds the admin URLs to the Echo instance

func (*API) AddQueryPaths

func (api *API) AddQueryPaths()

AddQueryPaths adds the two query URLs to the Echo instance

func (*API) ListenAndServe

func (api *API) ListenAndServe()

ListenAndServe starts the API server based on the config

type Config

type Config struct {
	// BasePath is the basepath for the API
	BasePath string
	// BasePathAdmin is the basepath for the Admin API
	BasePathAdmin string
	// ListenAddr is the address to listen on
	ListenAddr string
	// IsTLS is a flag to enable TLS
	IsTLS bool
	// TLSCert is the path to the TLS certificate
	TLSCert string
	// TLSKey is the path to the TLS key
	TLSKey string
	// AuthMethodAPI is the authentication method to use. Can be "none" or "basic"
	AuthMethodAPI string
	// AuthUsersAPI is a map of username:password for basic auth
	AuthUsersAPI map[string]string
	// AuthMethodAdmin is the authentication method to use. Can be "none" or "basic"
	AuthMethodAdmin string
	// AuthUsersAdmin is a map of username:password for basic auth
	AuthUsersAdmin map[string]string
	// Logger is the logger to use
	Logger *zerolog.Logger
	// RPS is the rate limit for the API
	RPS float64
}

Config struct is corresponding to the YAML payload in api section of the config file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL