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 Decoder
- type Handler
- type Registry
- func (r *Registry) CreateRequestDecoder(typ reflect.Type, paramKeys []string, caller *runtime.Func) (scan RequestDecoder, perm string, err error)
- func (r *Registry) Decoder(typ reflect.Type, tags reflect.StructTag) (dec Decoder, err error)
- func (s *Registry) DescribeOperation(op *openapi.Operation, in, out reflect.Type) (err error)
- func (r *Registry) Gatekeeper() security.Gatekeeper
- func (r *Registry) Handler(typ reflect.Type, tags reflect.StructTag, paramKeys []string, handler Handler) (scan Handler, err error)
- func (r *Registry) OptionalPermTag() bool
- func (r *Registry) Policies() *security.PolicyStore
- func (r *Registry) RegisterType(typs ...TypeRegistrar) (err error)
- func (r *Registry) Schema(typ reflect.Type, tag ...reflect.StructTag) (schema openapi.Schema, err error)
- type RequestDecoder
- 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 Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry(gatekeeper ...security.Gatekeeper) (r *Registry)
func (*Registry) CreateRequestDecoder ¶
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 RequestDecoder ¶
type RequestDecoder func(p unsafe.Pointer, c *fasthttp.RequestCtx) error
type TypeDescriber ¶
type TypeDescriber interface {
TypeDescription(reg *Registry) TypeDescription
}
type TypeDescription ¶
type TypeDescription struct {
// Documentation of request and response
Schema func(tags reflect.StructTag) (openapi.Schema, error)
// Handler of request and response
Handler func(tags reflect.StructTag, handler Handler) (Handler, error)
// Decoding of request value (e.g. query param)
Decoder func(tags reflect.StructTag) (Decoder, error)
}
func (TypeDescription) IsZero ¶
func (t TypeDescription) IsZero() bool
type TypeRegistrar ¶
type TypeRegistrar interface {
Type() reflect.Type
TypeDescriber
}
Click to show internal directories.
Click to hide internal directories.