parser

package
v0.0.6-beta Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTypeFieldRequired = errors.New("type field path is required")
	ErrTypeFieldNotFound = errors.New("type field not found")
	ErrTypeFieldNotStr   = errors.New("type field is not a string")
	ErrNoRegistryEntry   = errors.New("no registry entry for type")
	ErrUnsupportedFormat = errors.New("unsupported format")
)
View Source
var DefaultRegistry = Registry{}

Functions

func DecodePayload

func DecodePayload(raw string, format Format) ([]byte, error)

func DefaultCleaner

func DefaultCleaner(m map[string]any) map[string]any

func Parse

func Parse[T any](raw []byte, opts ...Option) (*T, error)

func ParseByType

func ParseByType(raw []byte, fieldPath string, reg Registry, opts ...Option) (any, error)

func ParseInto

func ParseInto(raw []byte, out any, opts ...Option) error

func ParseMap

func ParseMap(raw []byte, opts ...Option) (map[string]any, error)

func Register

func Register(name string, ctor func() any)

func ValidateStruct

func ValidateStruct(v any, val *validator.Validate) error

Types

type Cleaner

type Cleaner func(map[string]any) map[string]any

type Format

type Format string
const (
	FormatJSON Format = "json"
	FormatBSON Format = "bson"
)

type Option

type Option func(*config)

func WithCleaner

func WithCleaner(cl Cleaner) Option

func WithFormat

func WithFormat(f Format) Option

func WithValidation

func WithValidation(v bool) Option

func WithValidator

func WithValidator(v *validator.Validate) Option

type Registry

type Registry map[string]func() any

func NewRegistry

func NewRegistry() Registry

func (Registry) Register

func (r Registry) Register(name string, ctor func() any)

Jump to

Keyboard shortcuts

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