Documentation
¶
Index ¶
- Constants
- Variables
- func SerializerFromRuntime(runtimeInstance runtimecontract.Runtime) serializercontract.Serializer
- func SerializerMustFromRuntime(runtimeInstance runtimecontract.Runtime) serializercontract.Serializer
- type JsonSerializer
- type PlainTextSerializer
- type SerializerManager
- func NewSerializerManager(serializersByMime map[string]serializercontract.Serializer) (*SerializerManager, error)
- func SerializerManagerFromRuntime(runtimeInstance runtimecontract.Runtime) *SerializerManager
- func SerializerManagerMustFromRuntime(runtimeInstance runtimecontract.Runtime) *SerializerManager
Constants ¶
const ( MimeApplicationJson = "application/json" MimeTextPlain = "text/plain" )
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 ¶
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
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
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 (instance *SerializerManager) Get(mime string) (serializercontract.Serializer, bool)
func (*SerializerManager) ResolveByAcceptHeader ¶
func (instance *SerializerManager) ResolveByAcceptHeader(acceptHeader string) (serializercontract.Serializer, error)