registry

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 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)
)
View Source
var (
	NoParser = func(reflect.StructTag) (Parser, error) {
		return nil, nil
	}
)

Functions

func ScanTags

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

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

type Parser = scanner.Scanner

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) Binder added in v0.18.0

func (r *Registry) Binder(typ reflect.Type, fieldName string, tags reflect.StructTag) (_ Binder, err error)

func (*Registry) CreateBinder added in v0.18.0

func (r *Registry) CreateBinder(typ reflect.Type, paramKeys []string, caller *runtime.Func) (bind Binder, perm string, 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) OptionalPermTag added in v0.13.0

func (r *Registry) OptionalPermTag() bool

func (*Registry) Parser added in v0.18.0

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

Get a parser, or create one.

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) Responder added in v0.18.0

func (r *Registry) Responder(typ reflect.Type) (scan Responder, err error)

func (*Registry) Schema

func (r *Registry) Schema(typ reflect.Type, tag ...reflect.StructTag) (schema openapi.Schema, err error)

type Responder added in v0.18.0

type Responder func(c *fasthttp.RequestCtx, ptr unsafe.Pointer, next func() error) error

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
}

Jump to

Keyboard shortcuts

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