Documentation ¶
Index ¶
- Constants
- func CheckError(resp *http.Response) (err error)
- func CheckErrorStatus(code int, res *http.Response) error
- func ErrorCodeToStatusCode(ctx context.Context, code string) int
- func OrgIDFromContext(ctx context.Context) *platform.ID
- func SetCORS(next http.Handler) http.Handler
- func SkipOptions(next http.Handler) http.Handler
- func StatusCodeToErrorCode(statusCode int) string
- func UserAgent(r *http.Request) string
- func WriteErrorResponse(ctx context.Context, w http.ResponseWriter, code string, msg string)
- type API
- func (a *API) DecodeGob(r io.Reader, v interface{}) error
- func (a *API) DecodeJSON(r io.Reader, v interface{}) error
- func (a *API) Err(w http.ResponseWriter, r *http.Request, err error)
- func (a *API) Respond(w http.ResponseWriter, r *http.Request, status int, v interface{})
- func (a *API) Write(w http.ResponseWriter, status int, b []byte)
- type APIOptFn
- func WithEncodeGZIP() APIOptFn
- func WithErrFn(fn func(ctx context.Context, 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 OrgContext
- 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 ¶
func CheckError ¶
CheckError reads the http.Response and returns an error if one exists. It will automatically recognize the errors returned by Influx services and decode the error into an internal error type. If the error cannot be determined in that way, it will create a generic error message.
If there is no error, then this returns nil.
func CheckErrorStatus ¶
CheckErrorStatus for status and any error in the response.
func ErrorCodeToStatusCode ¶
ErrorCodeToStatusCode maps an influxdb error code string to a http status code integer.
func OrgIDFromContext ¶
OrgIDFromContext ....
func StatusCodeToErrorCode ¶
StatusCodeToErrorCode maps a http status code integer to an influxdb error code string.
func WriteErrorResponse ¶
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.