Documentation ¶
Index ¶
- Constants
- Variables
- func HTTPError(c echo.Context, err error, statusCode int)
- func UnescapedJSON(c echo.Context, code int, i interface{}) error
- type Config
- type CustomValidator
- type NormalizeBinder
- type Option
- func WithLogLevel(logLevel string) Option
- func WithMaxBytesToReadInBody(size string) Option
- func WithProtocol(protocol string) Option
- func WithReadHeaderTimeout(t time.Duration) Option
- func WithReadTimeout(t time.Duration) Option
- func WithRequestHandlerTimeout(t time.Duration) Option
- func WithThrottleLimit(limit int) Option
- func WithWriteTimeout(t time.Duration) Option
- type Server
- type ServerParams
Constants ¶
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 = "*" )
const TimeoutMessage = "Server Timeout!"
Variables ¶
Functions ¶
func UnescapedJSON ¶ added in v1.1.4
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.
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 WithMaxBytesToReadInBody ¶ added in v1.0.4
func WithProtocol ¶ added in v1.0.4
func WithReadHeaderTimeout ¶ added in v1.0.4
func WithReadTimeout ¶ added in v1.0.4
func WithRequestHandlerTimeout ¶ added in v1.0.4
func WithThrottleLimit ¶ added in v1.0.4
func WithWriteTimeout ¶ added in v1.0.4
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
GetURI returns the HTTP URI that the server is listening on.
func (*Server) ListenAndServe ¶ added in v1.0.4
@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 localhost:1234 @BasePath / @schemes http
ListenAndServe listens for and serves HTTP requests against the API server.