Documentation ¶
Overview ¶
Package encoding provides HTTP response encoding abstractions
Index ¶
Constants ¶
View Source
const (
// ContentTypeHeaderKey is the HTTP standard header name for content type.
ContentTypeHeaderKey = "RawHTML-type"
)
Variables ¶
View Source
var ( // EncDecProviders provides ResponseEncoders for dependency injection. EncDecProviders = wire.NewSet( ProvideServerEncoderDecoder, ProvideContentType, ) )
Functions ¶
This section is empty.
Types ¶
type ClientEncoder ¶
type ClientEncoder interface { ContentType() string Unmarshal(ctx context.Context, data []byte, v any) error Encode(ctx context.Context, dest io.Writer, v any) error EncodeReader(ctx context.Context, data any) (io.Reader, error) }
ClientEncoder is an encoder for a service client.
func ProvideClientEncoder ¶
func ProvideClientEncoder(logger logging.Logger, tracerProvider tracing.TracerProvider, encoding *contentType) ClientEncoder
ProvideClientEncoder provides a ClientEncoder.
type Config ¶
type Config struct { ContentType string `json:"contentType" toml:"content_type,omitempty"` // contains filtered or unexported fields }
Config configures input/output encoding for the service.
type ContentType ¶
type ContentType *contentType
ContentType is the publicly accessible version of contentType.
var ( // ContentTypeJSON is to indicate we want JSON for some reason. ContentTypeJSON ContentType = buildContentType(contentTypeJSON) // ContentTypeXML is to indicate we want XML for some reason. ContentTypeXML ContentType = buildContentType(contentTypeXML) // ContentTypeEmoji is to indicate we want Emoji for some reason. ContentTypeEmoji ContentType = buildContentType(contentTypeEmoji) )
func ProvideContentType ¶
func ProvideContentType(cfg Config) ContentType
ProvideContentType provides a ContentType from a Config.
type ServerEncoderDecoder ¶
type ServerEncoderDecoder interface { RespondWithData(ctx context.Context, res http.ResponseWriter, val any) EncodeResponseWithStatus(ctx context.Context, res http.ResponseWriter, val any, statusCode int) EncodeErrorResponse(ctx context.Context, res http.ResponseWriter, msg string, statusCode int) EncodeInvalidInputResponse(ctx context.Context, res http.ResponseWriter) EncodeNotFoundResponse(ctx context.Context, res http.ResponseWriter) EncodeUnspecifiedInternalServerErrorResponse(ctx context.Context, res http.ResponseWriter) EncodeInvalidPermissionsResponse(ctx context.Context, res http.ResponseWriter) DecodeRequest(ctx context.Context, req *http.Request, dest any) error DecodeBytes(ctx context.Context, payload []byte, dest any) error MustEncode(ctx context.Context, v any) []byte MustEncodeJSON(ctx context.Context, v any) []byte }
ServerEncoderDecoder is an interface that allows for multiple implementations of HTTP response formats.
func ProvideServerEncoderDecoder ¶
func ProvideServerEncoderDecoder(logger logging.Logger, tracerProvider tracing.TracerProvider, contentType ContentType) ServerEncoderDecoder
ProvideServerEncoderDecoder provides a ServerEncoderDecoder.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.