Documentation
¶
Index ¶
- Constants
- Variables
- type BinaryCodec
- type Codec
- type ImageCodec
- type JSONCodec
- type JSONLCodec
- type Registry
- func (r *Registry) Decode(doc io.Reader, contentType string) (any, error)
- func (r *Registry) DetectContentType(path string) string
- func (r *Registry) Encode(data any, contentType string) (io.Reader, error)
- func (r *Registry) Get(contentType string) (Codec, bool)
- func (r *Registry) GetByExtension(ext string) (Codec, bool)
- func (r *Registry) GetExtension(contentType string) string
- func (r *Registry) Register(c Codec)
- type TextCodec
- type YAMLCodec
Constants ¶
View Source
const ( ContentStream = "application/octet-stream" ContentJSON = "application/json" ContentJSONL = "application/jsonl" ContentYAML = "application/x-yaml" ContentPNG = "image/png" ContentJPG = "image/jpeg" ContentText = "text/plain" ContentMarkdown = "text/markdown" ContentEOF = "application/x-eof" // Signals end of stream )
Content type constants
Variables ¶
View Source
var Default = NewRegistry()
Default is the global default registry
Functions ¶
This section is empty.
Types ¶
type BinaryCodec ¶
type BinaryCodec struct{}
func (*BinaryCodec) ContentType ¶
func (c *BinaryCodec) ContentType() string
func (*BinaryCodec) Extensions ¶
func (c *BinaryCodec) Extensions() []string
type Codec ¶
type Codec interface {
// ContentType returns the MIME type this codec handles
ContentType() string
// Decode reads from io.Reader and converts to Go value
Decode(r io.Reader) (any, error)
// Encode converts Go value to bytes and writes to io.Writer
Encode(w io.Writer, data any) error
// Extensions returns common file extensions for this type
Extensions() []string
}
Codec handles encoding/decoding for a specific content type.
func NewBinaryCodec ¶
func NewBinaryCodec() Codec
func NewImageCodec ¶
func NewJSONCodec ¶
func NewJSONLCodec ¶
func NewJSONLCodec() Codec
func NewPrettyJSONCodec ¶
func NewTextCodec ¶
func NewYAMLCodec ¶
func NewYAMLCodec() Codec
type ImageCodec ¶
type ImageCodec struct {
// contains filtered or unexported fields
}
func (*ImageCodec) ContentType ¶
func (c *ImageCodec) ContentType() string
func (*ImageCodec) Extensions ¶
func (c *ImageCodec) Extensions() []string
type JSONCodec ¶
type JSONCodec struct {
// contains filtered or unexported fields
}
func (*JSONCodec) ContentType ¶
func (*JSONCodec) Extensions ¶
type JSONLCodec ¶
type JSONLCodec struct{}
func (*JSONLCodec) ContentType ¶
func (c *JSONLCodec) ContentType() string
func (*JSONLCodec) Extensions ¶
func (c *JSONLCodec) Extensions() []string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages codec instances.
func (*Registry) DetectContentType ¶
DetectContentType detects content type from file path
func (*Registry) GetByExtension ¶
GetByExtension returns codec for file extension
func (*Registry) GetExtension ¶
GetExtension returns the preferred file extension for a content type. Returns empty string if content type is not registered.
type TextCodec ¶
type TextCodec struct {
// contains filtered or unexported fields
}
func (*TextCodec) ContentType ¶
func (*TextCodec) Extensions ¶
type YAMLCodec ¶
type YAMLCodec struct{}
func (*YAMLCodec) ContentType ¶
func (*YAMLCodec) Extensions ¶
Click to show internal directories.
Click to hide internal directories.