serializer

package
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MimeApplicationJson = "application/json"
	MimeTextPlain       = "text/plain"
)
View Source
const (
	ServiceSerializer        = "service.serializer"
	ServiceSerializerManager = "service.serializer.manager"
)

ServiceSerializer is the default serializer — the json one, registered by the application boot behind a Has gate so an application or module registering it first substitutes it. It is what SerializerMustFromRuntime and SerializerFromRuntime answer.

ServiceSerializerManager is what content negotiation reads: the media type a response is served under is chosen by the manager from the request's Accept header. Registering a serializer under ServiceSerializer therefore changes what the two resolvers hand a caller, and what a request is served only on the fallback path the result handler takes when the manager is absent or the negotiation itself failed — to add a media type, register ServiceSerializerManager with a manager built by NewSerializerManager carrying the wider map.

Variables

View Source
var ErrNotAcceptable = errors.New("no acceptable media type for the accept header")

ErrNotAcceptable reports that the accept header refused every media type the manager can produce, so no representation can be served.

Functions

func SerializerFromRuntime

func SerializerFromRuntime(runtimeInstance runtimecontract.Runtime) serializercontract.Serializer

SerializerFromRuntime resolves the request serializer and answers nil when it cannot, with the failure logged through the soft logger resolver. The typed-nil branch is latent defense: the container refuses a provider-returned typed nil with an error today, so it is reachable only through a resolution path without that refusal — but a typed nil that slipped through would pass the plain comparison, look live to the result handler and dereference its nil receiver on the first Serialize of the request path.

func SerializerMustFromRuntime

func SerializerMustFromRuntime(runtimeInstance runtimecontract.Runtime) serializercontract.Serializer

Types

type JsonSerializer

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

func NewJsonSerializer

func NewJsonSerializer() *JsonSerializer

func NewPrettyJsonSerializer

func NewPrettyJsonSerializer() *JsonSerializer

func (*JsonSerializer) ContentType

func (instance *JsonSerializer) ContentType() string

func (*JsonSerializer) Deserialize

func (instance *JsonSerializer) Deserialize(payload []byte, target any) error

func (*JsonSerializer) Serialize

func (instance *JsonSerializer) Serialize(value any) ([]byte, error)

type PlainTextSerializer

type PlainTextSerializer struct {
}

func NewPlainTextSerializer

func NewPlainTextSerializer() *PlainTextSerializer

func (*PlainTextSerializer) ContentType

func (instance *PlainTextSerializer) ContentType() string

func (*PlainTextSerializer) Deserialize

func (instance *PlainTextSerializer) Deserialize(payload []byte, target any) error

func (*PlainTextSerializer) Serialize

func (instance *PlainTextSerializer) Serialize(value any) ([]byte, error)

type SerializerManager

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

func NewSerializerManager

func NewSerializerManager(serializersByMime map[string]serializercontract.Serializer) (*SerializerManager, error)

func SerializerManagerFromRuntime

func SerializerManagerFromRuntime(runtimeInstance runtimecontract.Runtime) *SerializerManager

func SerializerManagerMustFromRuntime

func SerializerManagerMustFromRuntime(runtimeInstance runtimecontract.Runtime) *SerializerManager

func (*SerializerManager) Get

func (*SerializerManager) ResolveByAcceptHeader

func (instance *SerializerManager) ResolveByAcceptHeader(acceptHeader string) (serializercontract.Serializer, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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