payload

package
v0.0.0-...-e537141 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StdCoders = Coders{
		JsonCoder: Json,
		XmlCoder:  Xml,
	}

	StdCoderMap = map[CoderID]HandlerFunc{
		CoderStdJSON: StdJSONFunc,
	}
)
View Source
var Json = Coder{
	Decoder: NewStdJsonDecoder(),
	Encoder: NewStdJsonEncoder(),
}
View Source
var Xml = Coder{
	Decoder: NewStdXmlDecoder(),
	Encoder: NewStdXmlEncoder(),
}

Functions

func AddStdCoders

func AddStdCoders(m *MultiCoder) (err error)

func DecodeSection

func DecodeSection(dec Decoder, r io.Reader, name string, v interface{}) (err error)

func GetSection

func GetSection(dec Decoder, r io.Reader, name string) (s string, err error)

func StdJSONFunc

func StdJSONFunc(req Request) error

Types

type Coder

type Coder struct {
	Encoder
	Decoder
}

type CoderCallback

type CoderCallback func(kind CoderKind, c Coder) (err error)

type CoderID

type CoderID string
const (
	CoderStdJSON CoderID = "json"
)

type CoderKind

type CoderKind string
const (
	JsonCoder CoderKind = "json"
	XmlCoder  CoderKind = "xml"
	CsvCoder  CoderKind = "csv"
)

type CoderNames

type CoderNames []string

type Coders

type Coders map[CoderKind]Coder

type DecodeRequest

type DecodeRequest struct {
	From io.Reader
	Into any
}

func (DecodeRequest) RequestKind

func (DecodeRequest) RequestKind() RequestKind

func (DecodeRequest) ToEnumRequest

func (d DecodeRequest) ToEnumRequest(t TagToType) EnumDecodeRequest

type Decoder

type Decoder interface {
	Decode(r io.Reader, v interface{}) (err error)
}

type Deps

type Deps struct {
	Logger *slog.Logger
}

type EncodeRequest

type EncodeRequest struct {
	Into io.Writer
	From any
}

func (EncodeRequest) RequestKind

func (EncodeRequest) RequestKind() RequestKind

func (EncodeRequest) ToEnumRequest

func (e EncodeRequest) ToEnumRequest(t TagToType) EnumEncodeRequest

type Encoder

type Encoder interface {
	Encode(w io.Writer, v interface{}) (err error)
}

type Enum

type Enum struct {
	Tag  string          `json:"tag"`
	Data json.RawMessage `json:"data"`
}

func EnumFromBytes

func EnumFromBytes(tag string, data []byte) Enum

func EnumFromString

func EnumFromString(tag string, data string) Enum

type EnumDecode

type EnumDecode func(TagToType, io.Reader, any) error

type EnumDecodeRequest

type EnumDecodeRequest struct {
	DecodeRequest DecodeRequest
	TagToType     TagToType
}

type EnumDecoder

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

func NewEnumDecoder

func NewEnumDecoder(dec Decoder) EnumDecoder

func (EnumDecoder) EnumDecode

func (ed EnumDecoder) EnumDecode(tt TagToType, r io.Reader, into any) error

type EnumEncodeRequest

type EnumEncodeRequest struct {
	EncodeRequest EncodeRequest
	TagToType     TagToType
}

type EnumMethods

type EnumMethods struct {
	AsTagToType func(TagToAny) TagToType
	Decode      func(Deps, EnumDecodeRequest) error
	Encode      func(Deps, EnumEncodeRequest) error
}

type HandlerFunc

type HandlerFunc func(Request) error

func (HandlerFunc) Decode

func (h HandlerFunc) Decode(r io.Reader, val any) error

func (HandlerFunc) Encode

func (h HandlerFunc) Encode(w io.Writer, val any) error

type LogDecoder

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

type MultiCoder

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

func MustSetupMultiCoder

func MustSetupMultiCoder(fn MultiSetupFn) (m MultiCoder)

func SetupMultiCoder

func SetupMultiCoder(fn MultiSetupFn) (m MultiCoder, err error)

func StdMultiCoder

func StdMultiCoder() (m MultiCoder, err error)

func (MultiCoder) AvailableCoders

func (m MultiCoder) AvailableCoders() (names CoderNames)

func (MultiCoder) GetCoder

func (m MultiCoder) GetCoder(kind CoderKind) (c Coder, err error)

func (*MultiCoder) SetCoder

func (m *MultiCoder) SetCoder(kind CoderKind, c Coder) (err error)

func (*MultiCoder) SetCoders

func (m *MultiCoder) SetCoders(c Coders) (err error)

func (MultiCoder) TryAllCoders

func (m MultiCoder) TryAllCoders(cb CoderCallback) (err error)

func (MultiCoder) UseCoder

func (m MultiCoder) UseCoder(kind CoderKind, cb CoderCallback) (err error)

type MultiSetupFn

type MultiSetupFn func(m *MultiCoder) (err error)

type PartDecoder

type PartDecoder interface {
	DecodePart(r io.Reader, name string, v interface{}) (err error)
}

type Request

type Request interface {
	RequestKind() RequestKind
}

type RequestKind

type RequestKind int
const (
	RequestDecode RequestKind = iota
	RequestEncode
)

type StdJsonDecoder

type StdJsonDecoder struct{}

func NewStdJsonDecoder

func NewStdJsonDecoder() (s *StdJsonDecoder)

func (*StdJsonDecoder) Decode

func (*StdJsonDecoder) Decode(r io.Reader, v interface{}) (err error)

type StdJsonEncoder

type StdJsonEncoder struct{}

func NewStdJsonEncoder

func NewStdJsonEncoder() (s *StdJsonEncoder)

func (*StdJsonEncoder) Encode

func (*StdJsonEncoder) Encode(w io.Writer, v interface{}) (err error)

type StdXmlDecoder

type StdXmlDecoder struct{}

func NewStdXmlDecoder

func NewStdXmlDecoder() (s *StdXmlDecoder)

func (*StdXmlDecoder) Decode

func (*StdXmlDecoder) Decode(r io.Reader, v interface{}) (err error)

type StdXmlEncoder

type StdXmlEncoder struct{}

func NewStdXmlEncoder

func NewStdXmlEncoder() (s *StdXmlEncoder)

func (*StdXmlEncoder) Encode

func (*StdXmlEncoder) Encode(w io.Writer, v interface{}) (err error)

type TagToAny

type TagToAny map[string]any

func (TagToAny) AsTagToType

func (t TagToAny) AsTagToType() TagToType

type TagToType

type TagToType map[string]reflect.Type

type TypeTags

type TypeTags map[reflect.Type]TagToType

Jump to

Keyboard shortcuts

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