codec

package
v0.0.0-...-eadd4a4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Encode(w io.Writer, v any) error
	Decode(r io.Reader, v any) error
}

Codec handles serialization and deserialization for a specific media type.

func Lookup

func Lookup(r *http.Request, contentType string) (string, Codec)

Lookup finds the Codec for the given Content-Type. Falls back to JSON when no match is found.

type CodecRegistry

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

CodecRegistry maps media types to Codec implementations and injects itself into the request context. It implements plugin.ContextInjector — the framework injects it on every request automatically.

func NewCodecRegistry

func NewCodecRegistry() *CodecRegistry

NewCodecRegistry creates an empty CodecRegistry.

func (*CodecRegistry) Inject

func (cr *CodecRegistry) Inject(r *http.Request) *http.Request

Inject implements plugin.ContextInjector, storing the registry in the request context.

func (*CodecRegistry) Register

func (cr *CodecRegistry) Register(mediaType string, c Codec)

Register adds or replaces the Codec for the given media type.

type JsonCodec

type JsonCodec struct{}

JsonCodec is the built-in Codec for application/json. Auto-registered by the framework — no setup required.

func (*JsonCodec) Decode

func (c *JsonCodec) Decode(r io.Reader, v any) error

func (*JsonCodec) Encode

func (c *JsonCodec) Encode(w io.Writer, v any) error

type MsgpackCodec

type MsgpackCodec struct{}

MsgpackCodec provides application/msgpack serialization and deserialization. It implements plugin.Installer to register itself into the CodecRegistry at startup.

router.AddPlugin(&codec.MsgpackCodec{})

func (*MsgpackCodec) Decode

func (c *MsgpackCodec) Decode(r io.Reader, v any) error

func (*MsgpackCodec) Encode

func (c *MsgpackCodec) Encode(w io.Writer, v any) error

func (*MsgpackCodec) Install

func (c *MsgpackCodec) Install(ctx plugin.PluginContext)

type TextCodec

type TextCodec struct{}

TextCodec is the built-in Codec for text/plain. Auto-registered by the framework — no setup required.

func (*TextCodec) Decode

func (c *TextCodec) Decode(r io.Reader, v any) error

func (*TextCodec) Encode

func (c *TextCodec) Encode(w io.Writer, v any) error

type XmlCodec

type XmlCodec struct{}

XmlCodec provides application/xml serialization and deserialization. It implements plugin.Installer to register itself into the CodecRegistry at startup.

router.AddPlugin(&codec.XmlCodec{})

func (*XmlCodec) Decode

func (c *XmlCodec) Decode(r io.Reader, v any) error

func (*XmlCodec) Encode

func (c *XmlCodec) Encode(w io.Writer, v any) error

func (*XmlCodec) Install

func (c *XmlCodec) Install(ctx plugin.PluginContext)

type YamlCodec

type YamlCodec struct{}

YamlCodec provides application/yaml serialization and deserialization. It implements plugin.Installer to register itself into the CodecRegistry at startup.

router.AddPlugin(&codec.YamlCodec{})

func (*YamlCodec) Decode

func (c *YamlCodec) Decode(r io.Reader, v any) error

func (*YamlCodec) Encode

func (c *YamlCodec) Encode(w io.Writer, v any) error

func (*YamlCodec) Install

func (c *YamlCodec) Install(ctx plugin.PluginContext)

Jump to

Keyboard shortcuts

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