Documentation ¶
Index ¶
- Constants
- func SetCORS(next http.Handler) http.Handler
- func SkipOptions(next http.Handler) http.Handler
- func UserAgent(r *http.Request) string
- type API
- type APIOptFn
- func WithEncodeGZIP() APIOptFn
- func WithErrFn(fn func(err error) (interface{}, int, error)) APIOptFn
- func WithLog(logger *zap.Logger) APIOptFn
- func WithOKErrFn(fn func(err error) error) APIOptFn
- func WithPrettyJSON(b bool) APIOptFn
- func WithUnmarshalErrFn(fn func(encoding string, err error) error) APIOptFn
- type ErrBody
- type ErrorHandler
- type Middleware
- type ResourceHandler
- type StatusResponseWriter
Constants ¶
const PlatformErrorCodeHeader = "X-Platform-Error-Code"
PlatformErrorCodeHeader shows the error code of platform error.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API provides a consolidated means for handling API interface concerns. Concerns such as decoding/encoding request and response bodies as well as adding headers for content type and content encoding.
func (*API) DecodeJSON ¶
DecodeJSON decodes reader with json.
type APIOptFn ¶
type APIOptFn func(*API)
APIOptFn is a functional option for setting fields on the API type.
func WithEncodeGZIP ¶
func WithEncodeGZIP() APIOptFn
WithEncodeGZIP sets the encoder to gzip contents.
func WithOKErrFn ¶
WithOKErrFn is an error handler for failing validation for request bodies.
func WithPrettyJSON ¶
WithPrettyJSON sets the json encoder to marshal indent or not.
type ErrorHandler ¶
type ErrorHandler int
ErrorHandler is the error handler in http package.
func (ErrorHandler) HandleHTTPError ¶
func (h ErrorHandler) HandleHTTPError(ctx context.Context, err error, w http.ResponseWriter)
HandleHTTPError encodes err with the appropriate status code and format, sets the X-Platform-Error-Code headers on the response. We're no longer using X-Influx-Error and X-Influx-Reference. and sets the response status to the corresponding status code.
type Middleware ¶
Middleware constructor.
func Metrics ¶
func Metrics(name string, reqMetric *prometheus.CounterVec, durMetric *prometheus.HistogramVec) Middleware
func Trace ¶
func Trace(name string) Middleware
type ResourceHandler ¶
ResourceHandler is an HTTP handler for a resource. The prefix describes the url path prefix that relates to the handler endpoints.
type StatusResponseWriter ¶
type StatusResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
func NewStatusResponseWriter ¶
func NewStatusResponseWriter(w http.ResponseWriter) *StatusResponseWriter
func (*StatusResponseWriter) Code ¶
func (w *StatusResponseWriter) Code() int
func (*StatusResponseWriter) ResponseBytes ¶
func (w *StatusResponseWriter) ResponseBytes() int
func (*StatusResponseWriter) StatusCodeClass ¶
func (w *StatusResponseWriter) StatusCodeClass() string
func (*StatusResponseWriter) WriteHeader ¶
func (w *StatusResponseWriter) WriteHeader(statusCode int)
WriteHeader writes the header and captures the status code.