Documentation
¶
Index ¶
- Constants
- func GetDecompressedRequestBody(req *fasthttp.Request, contentEncoding string) (io.ReadCloser, error)
- func GetDecompressedResponseBody(resp *fasthttp.Response, contentEncoding string) (io.ReadCloser, error)
- func IsShutdown(err error) bool
- func LogRequestResponseAtTraceLevel(ctx *fasthttp.RequestCtx, logger *logrus.Logger)
- func NewRequestError(err error, status int) error
- func NewShutdownError(message string) error
- func Respond(ctx *fasthttp.RequestCtx, data interface{}, statusCode int) error
- func RespondAPIModeErrors(ctx *fasthttp.RequestCtx, code, message string) error
- func RespondError(ctx *fasthttp.RequestCtx, statusCode int, statusHeader string) error
- func RespondGraphQLErrors(ctx *fasthttp.Response, errors error) error
- type APIModeApp
- type APIModeResponse
- type APIModeResponseSummary
- type App
- type AppAdditionalOptions
- type Error
- type ErrorResponse
- type FieldError
- type FieldTypeError
- type Handler
- type Middleware
- type ValidationError
Constants ¶
const ( Playground = "playground" ValidationStatus = "APIFW-Validation-Status" XWallarmSchemaIDHeader = "X-WALLARM-SCHEMA-ID" ValidationDisable = "disable" ValidationBlock = "block" ValidationLog = "log_only" RequestProxyNoChecks = "proxy_request_no_checks" RequestProxyFailed = "proxy_failed" RequestProxyNoRoute = "proxy_no_route" RequestBlocked = "request_blocked" ResponseBlocked = "response_blocked" ResponseStatusNotFound = "response_status_not_found" APIMode = "api" ProxyMode = "proxy" GraphQLMode = "graphql" AnyMethod = "any" RequestID = "__wallarm_apifw_request_id" )
const ( APIModePostfixStatusCode = "_status_code" APIModePostfixValidationErrors = "_validation_errors" GlobalResponseStatusCodeKey = "global_response_status_code" RequestSchemaID = "__wallarm_apifw_request_schema_id" )
Variables ¶
This section is empty.
Functions ¶
func GetDecompressedRequestBody ¶ added in v0.6.11
func GetDecompressedRequestBody(req *fasthttp.Request, contentEncoding string) (io.ReadCloser, error)
GetDecompressedRequestBody function returns the Reader of the decompressed request body
func GetDecompressedResponseBody ¶ added in v0.6.11
func GetDecompressedResponseBody(resp *fasthttp.Response, contentEncoding string) (io.ReadCloser, error)
GetDecompressedResponseBody function returns the Reader of the decompressed response body
func IsShutdown ¶
IsShutdown checks to see if the shutdown error is contained in the specified error value.
func LogRequestResponseAtTraceLevel ¶ added in v0.6.12
func LogRequestResponseAtTraceLevel(ctx *fasthttp.RequestCtx, logger *logrus.Logger)
func NewRequestError ¶
NewRequestError wraps a provided error with an HTTP status code. This function should be used when handlers encounter expected errors.
func NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal a graceful shutdown.
func Respond ¶
func Respond(ctx *fasthttp.RequestCtx, data interface{}, statusCode int) error
Respond converts a Go value to JSON and sends it to the client.
func RespondAPIModeErrors ¶ added in v0.7.0
func RespondAPIModeErrors(ctx *fasthttp.RequestCtx, code, message string) error
RespondAPIModeErrors sends API mode specific response back to the client
func RespondError ¶
func RespondError(ctx *fasthttp.RequestCtx, statusCode int, statusHeader string) error
RespondError sends an error response back to the client.
Types ¶
type APIModeApp ¶ added in v0.6.14
type APIModeApp struct { Routers map[int]*router.Router Log *logrus.Logger // contains filtered or unexported fields }
APIModeApp 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 NewAPIModeApp ¶ added in v0.6.14
func NewAPIModeApp(lock *sync.RWMutex, passOPTIONS bool, storedSpecs database.DBOpenAPILoader, shutdown chan os.Signal, logger *logrus.Logger, mw ...Middleware) *APIModeApp
NewAPIModeApp creates an APIModeApp value that handle a set of routes for the set of application.
func (*APIModeApp) APIModeHandler ¶ added in v0.6.14
func (a *APIModeApp) APIModeHandler(ctx *fasthttp.RequestCtx)
APIModeHandler routes request to the appropriate handler according to the OpenAPI specification schema ID
func (*APIModeApp) Handle ¶ added in v0.6.14
func (a *APIModeApp) Handle(schemaID int, method string, path string, handler Handler, mw ...Middleware)
Handle is our mechanism for mounting Handlers for a given HTTP verb and path pair, this makes for really easy, convenient routing.
func (*APIModeApp) SetDefaultBehavior ¶ added in v0.6.14
func (a *APIModeApp) SetDefaultBehavior(schemaID int, handler Handler, mw ...Middleware)
func (*APIModeApp) SignalShutdown ¶ added in v0.6.14
func (a *APIModeApp) SignalShutdown()
SignalShutdown is used to gracefully shutdown the app when an integrity issue is identified.
type APIModeResponse ¶ added in v0.6.14
type APIModeResponse struct { Summary []*APIModeResponseSummary `json:"summary"` Errors []*ValidationError `json:"errors,omitempty"` }
type APIModeResponseSummary ¶ added in v0.6.14
type App ¶
type App struct { Router *router.Router Log *logrus.Logger Options *AppAdditionalOptions // 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 ¶
func NewApp(options *AppAdditionalOptions, shutdown chan os.Signal, logger *logrus.Logger, mw ...Middleware) *App
NewApp creates an App value that handle a set of routes for the application.
func (*App) Handle ¶
func (a *App) Handle(method string, path string, handler Handler, mw ...Middleware)
Handle is our mechanism for mounting Handlers for a given HTTP verb and path pair, this makes for really easy, convenient routing.
func (*App) SetDefaultBehavior ¶
func (a *App) SetDefaultBehavior(handler Handler, mw ...Middleware)
func (*App) SignalShutdown ¶
func (a *App) SignalShutdown()
SignalShutdown is used to gracefully shutdown the app when an integrity issue is identified.
type AppAdditionalOptions ¶ added in v0.6.13
type Error ¶
type Error struct { Err error Status int Fields []FieldError }
Error is used to pass an error during the request through the application with web specific context.
type ErrorResponse ¶
type ErrorResponse struct { Error string `json:"error"` Fields []FieldError `json:"fields,omitempty"` }
ErrorResponse is the form used for API responses from failures in the API.
type FieldError ¶
FieldError is used to indicate an error with a specific request field.
type FieldTypeError ¶ added in v0.6.14
type Handler ¶
type Handler func(ctx *fasthttp.RequestCtx) error
A Handler is a type that handles an http request within our own little mini framework.
func NewFastHTTPHandler ¶ added in v0.6.13
NewFastHTTPHandler wraps net/http handler to fasthttp request handler, so it can be passed to fasthttp server.
While this function may be used for easy switching from net/http to fasthttp, it has the following drawbacks comparing to using manually written fasthttp request handler:
- A lot of useful functionality provided by fasthttp is missing from net/http handler.
- net/http -> fasthttp handler conversion has some overhead, so the returned handler will be always slower than manually written fasthttp handler.
So it is advisable using this function only for quick net/http -> fasthttp switching. Then manually convert net/http handlers to fasthttp handlers according to https://github.com/valyala/fasthttp#switching-from-nethttp-to-fasthttp .
type Middleware ¶
Middleware is a function designed to run some code before and/or after another Handler. It is designed to remove boilerplate or other concerns not direct to any given Handler.
type ValidationError ¶ added in v0.6.14
type ValidationError struct { Message string `json:"message"` Code string `json:"code"` SchemaVersion string `json:"schema_version,omitempty"` SchemaID *int `json:"schema_id"` Fields []string `json:"related_fields,omitempty"` FieldsDetails []FieldTypeError `json:"related_fields_details,omitempty"` }