Documentation
¶
Overview ¶
Example (CreateTagScanner) ¶
type Foo struct {
A string `tag:"a"`
B int `tag:"b"`
C float64 `tag:"c"`
D bool `tag:"d"`
E bool `tag:"flags:e"`
F bool `tag:"flags:f"`
G bool `tag:"flags:g"`
}
reg := NewRegistry()
scan, err := reg.createTagScanner(reflect.TypeFor[Foo]())
if err != nil {
panic(err)
}
tags := reflect.StructTag(`a:"foobar" b:"123" c:"456.789" d:"true" h:"nothing" flags:"f,g,x"`)
var foo Foo
if err = scan(unsafe.Pointer(&foo), string(tags)); err != nil {
return
}
fmt.Printf("%#v\n", foo)
Output: registry.Foo{A:"foobar", B:123, C:456.789, D:true, E:false, F:true, G:true}
Index ¶
- Variables
- func ScanTags[T any](reg *Registry, dst *T, tags reflect.StructTag) (err error)
- type Binder
- type Parser
- type Registry
- func (r *Registry) Binder(typ reflect.Type, fieldName string, tags reflect.StructTag) (_ Binder, err error)
- func (r *Registry) CreateBinder(typ reflect.Type, paramKeys []string, caller *runtime.Func) (bind Binder, perm string, err error)
- func (s *Registry) DescribeOperation(op *openapi.Operation, in, out reflect.Type) (err error)
- func (r *Registry) Gatekeeper() security.Gatekeeper
- func (r *Registry) OptionalPermTag() bool
- func (r *Registry) Parser(typ reflect.Type, tags reflect.StructTag) (dec Parser, err error)
- func (r *Registry) Policies() *security.PolicyStore
- func (r *Registry) RegisterType(typs ...TypeRegistrar) (err error)
- func (r *Registry) Responder(typ reflect.Type) (scan Responder, err error)
- func (r *Registry) Schema(typ reflect.Type, tag ...reflect.StructTag) (schema openapi.Schema, err error)
- type Responder
- type TypeDescriber
- type TypeDescription
- type TypeRegistrar
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrFailedDecodeBody = errors.NewFrozenError("FAILED_DECODE_BODY", "Could not decode JSON body", 400) ErrFailedDecodeParam = errors.NewFrozenError("FAILED_DECODE_PARAM", "Could not decode URL param", 400) ErrFailedDecodeQuery = errors.NewFrozenError("FAILED_DECODE_QUERY", "Could not decode query param", 400) )
Functions ¶
Types ¶
type Binder ¶ added in v0.18.0
type Binder func(c *fasthttp.RequestCtx, ptr unsafe.Pointer) error
Binder populates a value from the request context (body, multipart, streaming). Input-only; runs before user handler; may short-circuit.
type Parser ¶ added in v0.18.0
Parser converts a single string (e.g. from query, path, header) into a value. Input-only; no ctx access, no response writes.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry(gatekeeper ...security.Gatekeeper) (r *Registry)
func (*Registry) CreateBinder ¶ added in v0.18.0
func (*Registry) DescribeOperation ¶
func (*Registry) Gatekeeper ¶ added in v0.13.0
func (r *Registry) Gatekeeper() security.Gatekeeper
Could be nil.
func (*Registry) OptionalPermTag ¶ added in v0.13.0
func (*Registry) Policies ¶ added in v0.13.0
func (r *Registry) Policies() *security.PolicyStore
func (*Registry) RegisterType ¶
func (r *Registry) RegisterType(typs ...TypeRegistrar) (err error)
type Responder ¶ added in v0.18.0
Responder shapes/streams the response around user code. Output-only; must call next() exactly once (unless short-circuiting).
type TypeDescriber ¶
type TypeDescriber interface {
TypeDescription(reg *Registry) TypeDescription
}
type TypeDescription ¶
type TypeDescription struct {
// Schema describes the type for OpenAPI (structure, format, content-type).
Schema func(tags reflect.StructTag) (openapi.Schema, error)
// Parser provides a string→value parser for this type (query/param/header).
Parser func(tags reflect.StructTag) (Parser, error)
// Binder provides a ctx-aware binder for this type (body, multipart, etc.).
// Preferred over Parser if both are defined.
Binder func(fieldName string, tags reflect.StructTag) (Binder, error)
// Responder provides an output wrapper/encoder for this type.
// Runs after user handler to write/stream the response.
Responder func() (Responder, error)
}
TypeDescription declares how a type behaves in the API framework. A type may implement any subset depending on if it's used for input, output, or both.
func (TypeDescription) IsZero ¶
func (t TypeDescription) IsZero() bool
type TypeRegistrar ¶
type TypeRegistrar interface {
Type() reflect.Type
TypeDescriber
}
Source Files
¶
- error.go
- operation.go
- registry.go
- registry_binder.go
- registry_parser.go
- registry_responder.go
- registry_schema.go
- request_handler.go
- request_handler_custom.go
- request_handler_form.go
- request_handler_json.go
- request_handler_multipart.go
- request_handler_param.go
- request_handler_query.go
- tag_scanner.go
- type_description.go
Click to show internal directories.
Click to hide internal directories.