httpmux

package
v0.0.0-...-8078c5c Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataKeyExpires = "x-expires"
View Source
const MetadataKeyStatusCode = "x-http-code"

Variables

This section is empty.

Functions

func FilterBodyOn204

func FilterBodyOn204(inner http.Handler) (http.Handler, error)

func GetExpiresHeader

func GetExpiresHeader(ctx context.Context) (string, bool)

func GetStatusCode

func GetStatusCode(ctx context.Context) (int, bool)

func MarshalAsJSON

func MarshalAsJSON(obj proto.Message) ([]byte, error)

func SetExpiresHeader

func SetExpiresHeader(ctx context.Context, expiresAt time.Time)

func SetStatusCode

func SetStatusCode(ctx context.Context, code int)

Types

type ErrorResponse

type ErrorResponse struct {
	Code    int                    `json:"code,omitempty"`
	Message string                 `json:"message,omitempty"`
	Status  string                 `json:"status,omitempty"`
	Errors  []ErrorResponseDetails `json:"errors,omitempty"`
}

type ErrorResponseDetails

type ErrorResponseDetails struct {
	Domain  string `json:"domain,omitempty"`
	Message string `json:"message,omitempty"`
	Reason  string `json:"reason,omitempty"`
}

type Options

type Options struct {
	// If EmitUnpopulated is true, we will send empty proto fields (false / "" / 0 etc)
	// Some older APIs do this (e.g. cloudbilling)
	// While it likely doesn't matter, it makes golden testing easier to match.
	EmitUnpopulated bool
}

type ServeMux

type ServeMux struct {
	*runtime.ServeMux

	// RewriteError allows us to customize the error we return.
	// Error can be changed in-place.
	RewriteError func(ctx context.Context, error *ErrorResponse)

	// RewriteHeaders allows us to customize the headers we return.
	// Response is changed in-place.
	RewriteHeaders func(ctx context.Context, response http.ResponseWriter, payload proto.Message)
}

func NewServeMux

func NewServeMux(ctx context.Context, conn *grpc.ClientConn, opt Options, handlers ...func(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error) (*ServeMux, error)

NewServeMux constructs an http server with our error handling etc

Jump to

Keyboard shortcuts

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