Documentation ¶
Index ¶
- Constants
- func DefaultBindHeaderHook(c *fiber.Ctx, v reflect.Value) error
- func DefaultBindPathHook(c *fiber.Ctx, v reflect.Value) error
- func DefaultBindQueryHook(c *fiber.Ctx, v reflect.Value) error
- func DefaultBindingHook(c *fiber.Ctx, v reflect.Value) error
- func DefaultErrorHook(c *fiber.Ctx, e error) (int, interface{})
- func DefaultExecHook(c *fiber.Ctx, h fiber.Handler, fname string) error
- func DefaultRenderHook(c *fiber.Ctx, statusCode int, payload interface{})
- func Deprecated(b bool) func(*Route)
- func Description(s string) func(*Route)
- func GetRoutes() map[string]*Route
- func Handler(h interface{}, status int, options ...func(*Route)) fiber.Handler
- func MediaType() string
- func ParseTagKey(tag string) (string, error)
- func RegisterValidation(tagName string, validationFunc validator.Func) error
- func SetBindHeaderHook(bh BindHook)
- func SetBindHook(bh BindHook)
- func SetBindPathHook(bh BindHook)
- func SetBindQueryHook(bh BindHook)
- func SetErrorHook(eh ErrorHook)
- func SetExecHook(eh ExecHook)
- func SetRenderHook(rh RenderHook, mt string)
- func Summary(s string) func(*Route)
- func Tags(tags []string) func(*Route)
- type BindError
- type BindHook
- type ErrorHook
- type ExecHook
- type RenderHook
- type Route
- func (r *Route) GetDefaultStatusCode() int
- func (r *Route) GetDeprecated() bool
- func (r *Route) GetDescription() string
- func (r *Route) GetHandler() reflect.Value
- func (r *Route) GetPath() string
- func (r *Route) GetSummary() string
- func (r *Route) GetTags() []string
- func (r *Route) GetVerb() string
- func (r *Route) HandlerName() string
- func (r *Route) HandlerNameWithPackage() string
- func (r *Route) InputType() reflect.Type
- func (r *Route) OutputType() reflect.Type
Constants ¶
const ( QueryTag = "query" PathTag = "path" HeaderTag = "header" EnumTag = "enum" RequiredTag = "required" DefaultTag = "default" ValidationTag = "validate" ExplodeTag = "explode" )
Fields tags used by optic.
const DefaultMaxBodyBytes = 256 * 1024
DefaultMaxBodyBytes is the maximum allowed size of a request body in bytes.
Variables ¶
This section is empty.
Functions ¶
func DefaultBindHeaderHook ¶
func DefaultBindPathHook ¶
func DefaultBindQueryHook ¶
func DefaultBindingHook ¶
DefaultBindingHook is the default binding hook. It uses Gin JSON binding to bind the body parameters of the request to the input object of the handler. Ir teturns an error if Gin binding fails.
func DefaultErrorHook ¶
DefaultErrorHook is the default error hook. It returns a StatusBadRequest with a payload containing the error message.
func DefaultExecHook ¶
DefaultExecHook is the default exec hook. It simply executes the wrapping gin-handler with the given context.
func DefaultRenderHook ¶
func DefaultRenderHook(c *fiber.Ctx, statusCode int, payload interface{})
DefaultRenderHook is the default render hook. It marshals the payload to JSON, or returns an empty body if the payload is nil. If Gin is running in debug mode, the marshalled JSON is indented.
func Deprecated ¶
Deprecated set the deprecated flag of a route.
func Description ¶
Description set the description of a route.
func Handler ¶
Handler returns a Fiber HandlerFunc that wraps the handler passed in parameters. The handler may use the following signature:
func(*fiber.Ctx, [input object ptr]) ([output object], error)
Input and output objects are both optional. As such, the minimal accepted signature is:
func(*fiber.Ctx) error
The wrapping fiber-handler will bind the parameters from the query-string, path, body and headers, and handle the errors.
Handler will panic if the handler or its input/output values are of incompatible type.
func MediaType ¶
func MediaType() string
MediaType returns the current media type (MIME) used by the actual render hook.
func ParseTagKey ¶
ParseTagKey parses the given struct tag key and return the name of the field
func RegisterValidation ¶
RegisterValidation registers a custom validation on the validator.Validate instance of the package NOTE: calling this function may instantiate the validator itself. NOTE: this function is not thread safe, since the validator validation registration isn't
func SetBindHeaderHook ¶
func SetBindHeaderHook(bh BindHook)
SetBindQueryHook sets the given hook as the default binding hook.
func SetBindHook ¶
func SetBindHook(bh BindHook)
SetBindHook sets the given hook as the default binding hook.
func SetBindPathHook ¶
func SetBindPathHook(bh BindHook)
SetBindQueryHook sets the given hook as the default binding hook.
func SetBindQueryHook ¶
func SetBindQueryHook(bh BindHook)
SetBindQueryHook sets the given hook as the default binding hook.
func SetErrorHook ¶
func SetErrorHook(eh ErrorHook)
SetErrorHook sets the given hook as the default error handling hook.
func SetExecHook ¶
func SetExecHook(eh ExecHook)
SetExecHook sets the given hook as the default execution hook.
func SetRenderHook ¶
func SetRenderHook(rh RenderHook, mt string)
SetRenderHook sets the given hook as the default rendering hook. The media type is used to generate the OpenAPI specification.
Types ¶
type BindError ¶
type BindError struct {
// contains filtered or unexported fields
}
BindError is an error type returned when optic fails to bind parameters, to differentiate from errors returned by the handlers.
func (BindError) ValidationErrors ¶
func (be BindError) ValidationErrors() validator.ValidationErrors
ValidationErrors returns the errors from the validate process.
type BindHook ¶
BindHook is the hook called by the wrapping gin-handler when binding an incoming request to the optic-handler's input object.
func GetBindHeaderHook ¶
func GetBindHeaderHook() BindHook
GetBindQueryHook returns the current bind hook.
func GetBindPathHook ¶
func GetBindPathHook() BindHook
GetBindQueryHook returns the current bind hook.
func GetBindQueryHook ¶
func GetBindQueryHook() BindHook
GetBindQueryHook returns the current bind hook.
type ErrorHook ¶
ErrorHook lets you interpret errors returned by your handlers. After analysis, the hook should return a suitable http status code and and error payload. This lets you deeply inspect custom error types.
type ExecHook ¶
An ExecHook is the func called to handle a request. The default ExecHook simply calle the wrapping gin-handler with the gin context.
type RenderHook ¶
type RenderHook func(*fiber.Ctx, int, interface{})
RenderHook is the last hook called by the wrapping gin-handler before returning. It takes the Gin context, the HTTP status code and the response payload as parameters. Its role is to render the payload to the client to the proper format.
type Route ¶
type Route struct { fiber.Route // contains filtered or unexported fields }
A Route contains information about a optic-enabled route.
func GetRouteByHandler ¶
GetRouteByHandler returns the route information of the given wrapped handler.
func (*Route) GetDefaultStatusCode ¶
GetDefaultStatusCode returns the default status code of the route.
func (*Route) GetDeprecated ¶
GetDeprecated returns the deprecated flag of the route.
func (*Route) GetDescription ¶
GetDescription returns the description of the route.
func (*Route) GetHandler ¶
GetHandler returns the handler of the route.
func (*Route) GetSummary ¶
GetSummary returns the summary of the route.
func (*Route) GetTags ¶
GetTags generates a list of tags for the swagger spec from one route definition. It uses the first chunk of the path of the route as the tag (for example, in /foo/bar it will return the "foo" tag), unless specific tags have been defined with optic.Tags
func (*Route) HandlerName ¶
HandlerName returns the name of the route handler.
func (*Route) HandlerNameWithPackage ¶
HandlerNameWithPackage returns the full name of the rout handler with its package path.
func (*Route) InputType ¶
InputType returns the input type of the handler. If the type is a pointer to a concrete type, it is dereferenced.
func (*Route) OutputType ¶
OutputType returns the output type of the handler. If the type is a pointer to a concrete type, it is dereferenced.