publicapi

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AllowedCORSOrigin is the allowed origin for CORS requests.
	// Used to allow webui to connect to the backend API server.
	// TODO: make this more restricted or configurable
	AllowedCORSOrigin = "*"
)
View Source
const TimeoutMessage = "Server Timeout!"

Variables

View Source
var WebsocketUpgrader = websocket.Upgrader{
	CheckOrigin: func(r *http.Request) bool {

		return true
	},
}

Functions

func UnescapedJSON added in v1.1.4

func UnescapedJSON(c echo.Context, code int, i interface{}) error

UnescapedJSON writes a JSON response with unescaped HTML characters. This is useful for returning JSON responses that contain HTML, such as URLs with ampersands.

Types

type Config added in v1.0.4

type Config struct {
	// These are TCP connection deadlines and not HTTP timeouts. They don't control the time it takes for our handlers
	// to complete. Deadlines operate on the connection, so our server will fail to return a result only after
	// the handlers try to access connection properties
	// ReadHeaderTimeout is the amount of time allowed to read request headers
	ReadHeaderTimeout time.Duration
	// ReadTimeout is the maximum duration for reading the entire request, including the body
	ReadTimeout time.Duration
	// WriteTimeout is the maximum duration before timing out writes of the response.
	// It doesn't cancel the context and doesn't stop handlers from running even after failing the request.
	// It is for added safety and should be a bit longer than the request handler timeout for better error handling.
	WriteTimeout time.Duration

	// This represents maximum duration for handlers to complete, or else fail the request with 503 error code.
	RequestHandlerTimeout time.Duration

	// MaxBytesToReadInBody is used by safeHandlerFuncWrapper as the max size of body
	MaxBytesToReadInBody string

	// ThrottleLimit is the maximum number of requests per second
	ThrottleLimit int

	// Protocol
	Protocol string

	// LogLevel is the minimum log level to log requests
	LogLevel string
}

func DefaultConfig added in v1.0.4

func DefaultConfig() Config

DefaultConfig returns the default configuration for the public API server.

func NewConfig added in v1.0.4

func NewConfig(opts ...Option) *Config

type CustomValidator added in v1.0.4

type CustomValidator struct {
	// contains filtered or unexported fields
}

CustomValidator is a custom validator for echo framework that does the following: - Uses go-playground/validator for validation if validator tags are present - Uses Validate() method if the struct implements validatable interface

func NewCustomValidator added in v1.0.4

func NewCustomValidator() *CustomValidator

func (*CustomValidator) Validate added in v1.0.4

func (cv *CustomValidator) Validate(i interface{}) error

type NormalizeBinder added in v1.5.0

type NormalizeBinder struct {
	// contains filtered or unexported fields
}

NormalizeBinder is a custom binder that extends the default binder with normalization.

func NewNormalizeBinder added in v1.5.0

func NewNormalizeBinder() *NormalizeBinder

NewNormalizeBinder creates a new NormalizeBinder with the default binder.

func (*NormalizeBinder) Bind added in v1.5.0

func (cb *NormalizeBinder) Bind(i interface{}, c echo.Context) error

Bind binds and validates the request body, then normalizes if it implements the normalizable interface.

type Option added in v1.0.4

type Option func(*Config)

func WithLogLevel added in v1.0.4

func WithLogLevel(logLevel string) Option

func WithMaxBytesToReadInBody added in v1.0.4

func WithMaxBytesToReadInBody(size string) Option

func WithProtocol added in v1.0.4

func WithProtocol(protocol string) Option

func WithReadHeaderTimeout added in v1.0.4

func WithReadHeaderTimeout(t time.Duration) Option

func WithReadTimeout added in v1.0.4

func WithReadTimeout(t time.Duration) Option

func WithRequestHandlerTimeout added in v1.0.4

func WithRequestHandlerTimeout(t time.Duration) Option

func WithThrottleLimit added in v1.0.4

func WithThrottleLimit(limit int) Option

func WithWriteTimeout added in v1.0.4

func WithWriteTimeout(t time.Duration) Option

type Server added in v1.0.4

type Server struct {
	Router  *echo.Echo
	Address string
	Port    uint16

	TLSCertificateFile string
	TLSKeyFile         string
	// contains filtered or unexported fields
}

Server configures a node's public REST API.

func NewAPIServer

func NewAPIServer(params ServerParams) (*Server, error)

func (*Server) GetURI added in v1.0.4

func (apiServer *Server) GetURI() *url.URL

GetURI returns the HTTP URI that the server is listening on.

func (*Server) ListenAndServe added in v1.0.4

func (apiServer *Server) ListenAndServe(ctx context.Context) error

ListenAndServe listens for and serves HTTP requests against the API server.

func (*Server) Shutdown added in v1.0.4

func (apiServer *Server) Shutdown(ctx context.Context) error

Shutdown shuts down the http server

type ServerParams added in v1.0.4

type ServerParams struct {
	Router             *echo.Echo
	Address            string
	Port               uint16
	HostID             string
	AutoCertDomain     string
	AutoCertCache      string
	TLSCertificateFile string
	TLSKeyFile         string
	Config             Config
	Authorizer         authz.Authorizer
	Headers            map[string]string
}

Directories

Path Synopsis
client
v2
endpoint

Jump to

Keyboard shortcuts

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