api

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeMethodAndPathNotFound               = "method_and_path_not_found"
	ErrCodeRequiredBodyMissed                  = "required_body_missed"
	ErrCodeRequiredBodyParseError              = "required_body_parse_error"
	ErrCodeRequiredBodyParameterMissed         = "required_body_parameter_missed"
	ErrCodeRequiredBodyParameterInvalidValue   = "required_body_parameter_invalid_value"
	ErrCodeRequiredPathParameterMissed         = "required_path_parameter_missed"
	ErrCodeRequiredPathParameterInvalidValue   = "required_path_parameter_invalid_value"
	ErrCodeRequiredQueryParameterMissed        = "required_query_parameter_missed"
	ErrCodeRequiredQueryParameterInvalidValue  = "required_query_parameter_invalid_value"
	ErrCodeRequiredCookieParameterMissed       = "required_cookie_parameter_missed"
	ErrCodeRequiredCookieParameterInvalidValue = "required_cookie_parameter_invalid_value"
	ErrCodeRequiredHeaderMissed                = "required_header_missed"
	ErrCodeRequiredHeaderInvalidValue          = "required_header_invalid_value"

	ErrCodeSecRequirementsFailed = "required_security_requirements_failed"

	ErrCodeUnknownParameterFound = "unknown_parameter_found"

	ErrCodeUnknownValidationError = "unknown_validation_error"
)

Variables

View Source
var (
	ErrAuthHeaderMissed = errors.New("missing Authorization header")
	ErrAPITokenMissed   = errors.New("missing API keys for authorization")

	ErrMethodAndPathNotFound    = errors.New("method and path are not found")
	ErrRequiredBodyIsMissing    = errors.New("required body is missing")
	ErrMissedRequiredParameters = errors.New("required parameters missed")
)

Functions

func Handlers

func Handlers(lock *sync.RWMutex, cfg *config.APIMode, shutdown chan os.Signal, logger *logrus.Logger, storedSpecs database.DBOpenAPILoader, AllowedIPCache *allowiplist.AllowedIPsType, waf coraza.WAF) fasthttp.RequestHandler

Types

type App added in v0.7.1

type App struct {
	Routers map[int]*router.Mux
	Log     *logrus.Logger
	// contains filtered or unexported fields
}

App is the entrypoint into our application and what configures our context object for each of our http handlers. Feel free to add any configuration data/logic on this App struct

func NewApp added in v0.7.1

func NewApp(lock *sync.RWMutex, passOPTIONS bool, storedSpecs database.DBOpenAPILoader, shutdown chan os.Signal, logger *logrus.Logger, mw ...web.Middleware) *App

NewApp creates an App value that handle a set of routes for the set of application.

func (*App) APIModeRouteHandler added in v0.7.1

func (a *App) APIModeRouteHandler(ctx *fasthttp.RequestCtx)

APIModeRouteHandler routes request to the appropriate handler according to the OpenAPI specification schema ID

func (*App) Handle added in v0.7.1

func (a *App) Handle(schemaID int, method string, path string, handler router.Handler, mw ...web.Middleware) error

Handle is our mechanism for mounting Handlers for a given HTTP verb and path pair, this makes for really easy, convenient routing.

func (*App) SignalShutdown added in v0.7.1

func (a *App) SignalShutdown()

SignalShutdown is used to gracefully shutdown the app when an integrity issue is identified.

type Health

type Health struct {
	Build     string
	Logger    *logrus.Logger
	OpenAPIDB database.DBOpenAPILoader
}

func (*Health) Liveness

func (h *Health) Liveness(ctx *fasthttp.RequestCtx) error

Liveness returns simple status info if the service is alive. If the app is deployed to a Kubernetes cluster, it will also return pod, node, and namespace details via the Downward API. The Kubernetes environment variables need to be set within your Pod/Deployment manifest.

func (*Health) Readiness

func (h *Health) Readiness(ctx *fasthttp.RequestCtx) error

Readiness checks if the Fasthttp connection pool is ready to handle new requests.

type RequestValidator added in v0.7.1

type RequestValidator struct {
	CustomRoute   *loader.CustomRoute
	OpenAPIRouter *loader.Router
	Log           *logrus.Logger
	Cfg           *config.APIMode
	ParserPool    *fastjson.ParserPool
	SchemaID      int
}

func (*RequestValidator) Handler added in v0.7.1

func (s *RequestValidator) Handler(ctx *fasthttp.RequestCtx) error

Handler validates request and respond with 200, 403 (with error) or 500 status code

type SecurityRequirementsParameterIsMissingError added in v0.6.14

type SecurityRequirementsParameterIsMissingError struct {
	Field   string
	Message string
}

func (*SecurityRequirementsParameterIsMissingError) Error added in v0.6.14

Jump to

Keyboard shortcuts

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