registry

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2025 License: MIT Imports: 19 Imported by: 0

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

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

func ScanTags

func ScanTags[T any](reg *Registry, dst *T, tags reflect.StructTag) (err error)

Types

type Decoder

type Decoder = scanner.Scanner

type Handler

type Handler func(c *fasthttp.RequestCtx, in, out unsafe.Pointer) error

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry(gatekeeper ...security.Gatekeeper) (r *Registry)

func (*Registry) CreateRequestDecoder

func (r *Registry) CreateRequestDecoder(typ reflect.Type, paramKeys []string, caller *runtime.Func) (scan RequestDecoder, perm string, err error)

func (*Registry) Decoder

func (r *Registry) Decoder(typ reflect.Type, tags reflect.StructTag) (dec Decoder, err error)

func (*Registry) DescribeOperation

func (s *Registry) DescribeOperation(op *openapi.Operation, in, out reflect.Type) (err error)

func (*Registry) Gatekeeper added in v0.13.0

func (r *Registry) Gatekeeper() security.Gatekeeper

Could be nil.

func (*Registry) Handler

func (r *Registry) Handler(typ reflect.Type, tags reflect.StructTag, paramKeys []string, handler Handler) (scan Handler, err error)

func (*Registry) OptionalPermTag added in v0.13.0

func (r *Registry) OptionalPermTag() bool

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)

func (*Registry) Schema

func (r *Registry) Schema(typ reflect.Type, tag ...reflect.StructTag) (schema openapi.Schema, 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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL