Documentation ¶
Index ¶
- func Form(model interface{}, opts ...Options) flamego.Handler
- func JSON(model interface{}, opts ...Options) flamego.Handler
- func MultipartForm(model interface{}, opts ...Options) flamego.Handler
- func YAML(model interface{}, opts ...Options) flamego.Handler
- type Error
- type ErrorCategory
- type Errors
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Form ¶
Form returns a middleware handler that injects a new instance of the model with populated fields and binding.Errors for any deserialization, binding, or validation errors into the request context. The model instance fields are populated by deserializing the payload from both form-urlencoded data request body and URL query parameters.
func JSON ¶
JSON returns a middleware handler that injects a new instance of the model with populated fields and binding.Errors for any deserialization, binding, or validation errors into the request context. The model instance fields are populated by deserializing the JSON payload from the request body.
func MultipartForm ¶
MultipartForm returns a middleware handler that injects a new instance of the model with populated fields and binding.Errors for any deserialization, binding, or validation errors into the request context. It works much like binding.Form except it can parse multipart forms and handle file uploads.
func YAML ¶ added in v1.1.0
YAML returns a middleware handler that injects a new instance of the model with populated fields and binding.Errors for any deserialization, binding, or validation errors into the request context. The model instance fields are populated by deserializing the YAML payload from the request body.
Types ¶
type Error ¶
type Error struct { // Category is the type of the error. Category ErrorCategory `json:"category,omitempty"` // Err is the underlying error. Err error `json:"error,omitempty"` }
Error is an error with a category.
type ErrorCategory ¶
type ErrorCategory string
ErrorCategory represents the type of an error.
const ( ErrorCategoryDeserialization ErrorCategory = "deserialization" ErrorCategoryValidation ErrorCategory = "validation" )
type Errors ¶
type Errors []Error
Errors may be generated during deserialization, binding, or validation. This type is mapped to the context so you can inject it into your own handlers and use it in your application if you want all your errors to look the same.
type Options ¶
type Options struct { // ErrorHandler will be invoked automatically when errors occurred. Default is // to do nothing, but handlers may still use binding.Errors and do custom errors // handling. ErrorHandler flamego.Handler // Validator sets a custom validator instead of the default validator. Validator *validator.Validate // MaxMemory specifies the maximum amount of memory to be allowed when parsing a // multipart form. Default is 10 MiB. MaxMemory int64 }
Options contains options for binding.JSON, binding.Form middleware.