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 NewFastHTTPHandler(h http.Handler, isPlayground bool) router.Handler
- 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
- func WrapMiddleware(mw []Middleware, handler router.Handler) router.Handler
- type APIModeResponse
- type APIModeResponseSummary
- type App
- type AppAdditionalOptions
- type Error
- type ErrorResponse
- type FieldError
- type FieldTypeError
- type Middleware
- type ValidationError
Constants ¶
const ( APIModePostfixStatusCode = "_status_code" APIModePostfixValidationErrors = "_validation_errors" GlobalResponseStatusCodeKey = "global_response_status_code" RequestSchemaID = "__wallarm_apifw_request_schema_id" )
const ( Playground = "playground" ValidationStatus = "APIFW-Validation-Status" XWallarmSchemaIDHeader = "X-WALLARM-SCHEMA-ID" ValidationDisable = "disable" ValidationBlock = "block" ValidationLog = "log_only" PassRequestOPTIONS = "proxy_request_with_options_method" RequestProxyFailed = "proxy_failed" RequestProxyNoRoute = "proxy_no_route" RequestBlocked = "request_blocked" ResponseBlocked = "response_blocked" ResponseStatusNotFound = "response_status_not_found" APIMode = "api" ProxyMode = "proxy" GraphQLMode = "graphql" RequestID = "__wallarm_apifw_request_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 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 .
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.
func RespondGraphQLErrors ¶ added in v0.6.13
RespondGraphQLErrors sends errors back to the client via GraphQL
func WrapMiddleware ¶ added in v0.7.1
func WrapMiddleware(mw []Middleware, handler router.Handler) router.Handler
WrapMiddleware creates a new handler by wrapping middleware around a final handler. The middlewares' Handlers will be executed by requests in the order they are provided.
Types ¶
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.Mux 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 ¶
Handle is our mechanism for mounting Handlers for a given HTTP verb and path pair, this makes for really easy, convenient routing.
func (*App) MainHandler ¶ added in v0.7.1
func (a *App) MainHandler(ctx *fasthttp.RequestCtx)
MainHandler routes request to the OpenAPI validator (handler)
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 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"` }