registry

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 15 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, err := NewRegistry(internal.NewJSONPool(jsoniter.ConfigFastest))

if err != nil {
	panic(err)
}

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(json *internal.JSONPool) (r *Registry, err error)

func (*Registry) CreateRequestDecoder

func (r *Registry) CreateRequestDecoder(typ reflect.Type, paramKeys []string) (scan RequestDecoder, 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) Handler

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

func (*Registry) JSON

func (s *Registry) JSON() *internal.JSONPool

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 {

	// Request & response
	Schema func(tags reflect.StructTag) (openapi.Schema, error)

	// Request
	Handler func(tags reflect.StructTag, handler Handler) (Handler, error)

	// Response
	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