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 ( // Providers provides ResponseEncoders for dependency injection. Providers = wire.NewSet( ProvideServerEncoderDecoder, ProvideContentType, ) )
Functions ¶
This section is empty.
Types ¶
type ClientEncoder ¶
type ClientEncoder interface { ContentType() string Unmarshal(ctx context.Context, data []byte, v interface{}) error Encode(ctx context.Context, dest io.Writer, v interface{}) error EncodeReader(ctx context.Context, data interface{}) (io.Reader, error) }
ClientEncoder is an encoder for a service client.
func ProvideClientEncoder ¶
func ProvideClientEncoder(logger logging.Logger, encoding *contentType) ClientEncoder
ProvideClientEncoder provides a ClientEncoder.
type Config ¶
type Config struct { ContentType string `json:"content_type" mapstructure:"content_type" 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 what we use to indicate we want JSON for some reason. ContentTypeJSON ContentType = buildContentType(contentTypeJSON) // ContentTypeXML is what we use to indicate we want XML for some reason. ContentTypeXML ContentType = buildContentType(contentTypeXML) )
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 interface{}) EncodeResponseWithStatus(ctx context.Context, res http.ResponseWriter, val interface{}, 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 interface{}) error MustEncode(ctx context.Context, v interface{}) []byte MustEncodeJSON(ctx context.Context, v interface{}) []byte }
ServerEncoderDecoder is an interface that allows for multiple implementations of HTTP response formats.
func ProvideServerEncoderDecoder ¶
func ProvideServerEncoderDecoder(logger logging.Logger, contentType ContentType) ServerEncoderDecoder
ProvideServerEncoderDecoder provides a ServerEncoderDecoder.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.