publicapi

package
v1.1.2-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const TimeoutMessage = "Server Timeout!"

Variables

This section is empty.

Functions

func HTTPError added in v0.3.26

func HTTPError(c echo.Context, err error, statusCode int)

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

	// SkippedTimeoutPaths is a list of paths that should not be subject to the request handler timeout.
	SkippedTimeoutPaths []string

	// 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

	// EnableSwaggerUI is a flag to enable swagger UI
	EnableSwaggerUI bool
}

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 Option added in v1.0.4

type Option func(*Config)

func WithEnableSwaggerUI added in v1.0.4

func WithEnableSwaggerUI(enableSwaggerUI bool) Option

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 WithSkipTimeoutPaths added in v1.0.4

func WithSkipTimeoutPaths(paths []string) 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
@title			Bacalhau API
@description	This page is the reference of the Bacalhau REST API. Project docs are available at https://docs.bacalhau.org/. Find more information about Bacalhau at https://github.com/bacalhau-project/bacalhau.
@contact.name	Bacalhau Team
@contact.url	https://github.com/bacalhau-project/bacalhau
@contact.email	team@bacalhau.org
@license.name	Apache 2.0
@license.url	https://github.com/bacalhau-project/bacalhau/blob/main/LICENSE
@host			bootstrap.production.bacalhau.org:1234
@BasePath		/
@schemes		http

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
}

Directories

Path Synopsis
v2
endpoint

Jump to

Keyboard shortcuts

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