Documentation ¶
Index ¶
- Variables
- func AddTraceIDToContext(ctx context.Context, id uuid.UUID, wasProvided bool) context.Context
- func CheckContextTimeout(ctx context.Context, message string, cause error) error
- func CoreRequestContextMiddleware(next http.Handler) http.Handler
- func CreateDownstreamError(ctx context.Context, kind Kind, response *http.Response, body []byte, ...) error
- func CreateError(ctx context.Context, kind Kind, message string, cause error) error
- func FindConfigFilename(cfgDir, prefix string) string
- func GetLogEntryFromContext(ctx context.Context) *logrus.Entrydeprecated
- func GetLoggerFromContext(ctx context.Context) *logrus.Loggerdeprecated
- func GetTraceIDFromContext(ctx context.Context) uuid.UUID
- func HandleError(ctx context.Context, w http.ResponseWriter, kind Kind, message string, ...)
- func LoadAndValidateFromYAMLFileName(filename string, out validator.Validator) error
- func LoggerToContext(ctx context.Context, logger *logrus.Logger, entry *logrus.Entry) context.Contextdeprecated
- func NewBool(b bool) *bool
- func NewHTTPTestServer(handler http.Handler) *httptest.Server
- func NewInvalidHeaderError(param string, cause error) error
- func NewLoggingRoundTripper(name string, base http.RoundTripper) http.RoundTripper
- func NewString(s string) *string
- func NewUnstartedHTTPTestServer(handler http.Handler) *httptest.Server
- func NewZeroHeaderLengthError(param string) error
- func ProvisionRestResult(ctx context.Context) context.Context
- func RequestHeaderFromContext(ctx context.Context) http.Header
- func RequestHeaderToContext(ctx context.Context, header http.Header) context.Context
- func RespHeaderAndStatusFromContext(ctx context.Context) (header http.Header, status int)
- func RespHeaderAndStatusToContext(ctx context.Context, header http.Header, status int) context.Context
- func Timeout(timeout time.Duration, timeoutHandler http.Handler) func(next http.Handler) http.Handler
- func TimeoutHandler(h http.Handler, dt time.Duration, timeout http.Handler) http.Handler
- func TraceabilityMiddleware(next http.Handler) http.Handler
- func TryGetTraceIDFromContext(ctx context.Context) (uuid.UUID, bool)
- func UpdateResponseStatus(ctx context.Context, status int) error
- func WrappedError(err error, fields ...KV) error
- type Callback
- func DefaultCallback() Callback
- func NewCallback(config *config.GenCodeConfig, downstreamTimeOut time.Duration, ...) Callback
- func NewCallbackV2(config *config.GenCodeConfig, downstreamTimeOut time.Duration, ...) Callback
- func NewCallbackV3(config *config.GenCodeConfig, downstreamTimeOut time.Duration, ...) Callback
- func (g Callback) AddMiddleware(ctx context.Context, r chi.Router)
- func (g Callback) BasePath() string
- func (g Callback) Config() interface{}
- func (g Callback) DownstreamTimeoutContext(ctx context.Context) (context.Context, context.CancelFunc)
- func (g Callback) HandleError(ctx context.Context, w http.ResponseWriter, kind Kind, message string, ...)
- func (g Callback) MapError(ctx context.Context, err error) *HTTPError
- func (g Callback) WriteError(ctx context.Context, w http.ResponseWriter, httpError *HTTPError)
- type Config
- type CustomError
- type DownstreamError
- type ErrorKinder
- type ErrorWriter
- type HTTPError
- type InvalidHeaderError
- type KV
- type Kind
- type MockRoundTripper
- type RegexWithFallBack
- type RestResult
- type RestResultContextKey
- type ServerError
- type ZeroHeaderLengthError
Constants ¶
This section is empty.
Variables ¶
var ErrHandlerTimeout = errors.New("http: Handler timeout")
ErrHandlerTimeout is returned on ResponseWriter Write calls in handlers which have timed out.
Functions ¶
func AddTraceIDToContext ¶
func CheckContextTimeout ¶
func CreateDownstreamError ¶
func CreateError ¶
func FindConfigFilename ¶
func GetLogEntryFromContext
deprecated
func GetLoggerFromContext
deprecated
func HandleError ¶
func NewHTTPTestServer ¶ added in v0.175.0
NewHTTPTestServer returns a new httptest.Server with the given handler suitable for use within unit tests. The returned server comes equipped with the following: 1. log.Logger.
func NewInvalidHeaderError ¶ added in v0.258.0
func NewLoggingRoundTripper ¶
func NewLoggingRoundTripper(name string, base http.RoundTripper) http.RoundTripper
func NewUnstartedHTTPTestServer ¶ added in v0.175.0
NewHTTPTestServer returns an unstarted httptest.Server with the given handler suitable for use within unit tests. The returned server comes equipped with the following: 1. log.Logger.
func NewZeroHeaderLengthError ¶ added in v0.211.0
func ProvisionRestResult ¶ added in v0.69.0
ProvisionRestResult provisions within the context the ability to retrieve the result of a rest request.
func RequestHeaderFromContext ¶
RequestHeaderFromContext retrieves the request header from the context.
func RequestHeaderToContext ¶
RequestHeaderToContext creates a new context containing the request header.
func RespHeaderAndStatusFromContext ¶
RespHeaderAndStatusFromContext retrieves response header and status from the context.
func RespHeaderAndStatusToContext ¶
func RespHeaderAndStatusToContext(ctx context.Context, header http.Header, status int) context.Context
RespHeaderAndStatusToContext creates a new context containing the response header and status.
func Timeout ¶
func Timeout(timeout time.Duration, timeoutHandler http.Handler) func(next http.Handler) http.Handler
Timeout is a middleware that cancels ctx after a given timeout or call a special handler on timeout.
func TimeoutHandler ¶
TimeoutHandler returns a Handler that runs h with the given time limit.
The new Handler calls h.ServeHTTP to handle each request, but if a call runs for longer than its time limit, the handler calls the error handler which can then return a HTTP result however is deems correct. After such a timeout, writes by h to its ResponseWriter will return ErrHandlerTimeout.
TimeoutHandler supports the Pusher interface but does not support the Hijacker or Flusher interfaces.
func TraceabilityMiddleware ¶
Injects a traceId UUID into the request context.
func WrappedError ¶ added in v0.31.0
Types ¶
type Callback ¶
type Callback struct { DownstreamTimeout time.Duration RouterBasePath string UpstreamConfig validator.Validator MapErrorFunc func(ctx context.Context, err error) *HTTPError // MapErrorFunc may be left nil to use default behaviour. WriteErrorFunc func(ctx context.Context, w http.ResponseWriter, httpError *HTTPError) // WriteError may be left nil to use default behaviour. AddMiddlewareFunc func(ctx context.Context, r chi.Router) // AddMiddlewareFunc may be left nil to use default behaviour. }
func DefaultCallback ¶
func DefaultCallback() Callback
func NewCallback ¶ added in v0.175.0
func NewCallback( config *config.GenCodeConfig, downstreamTimeOut time.Duration, mapError func(ctx context.Context, err error) *HTTPError, ) Callback
NewCallback is deprecated, prefer NewCallbackV2.
func NewCallbackV2 ¶ added in v0.175.0
func NewCallbackV2( config *config.GenCodeConfig, downstreamTimeOut time.Duration, mapError func(ctx context.Context, err error) *HTTPError, addMiddleware func(ctx context.Context, r chi.Router), ) Callback
NewCallbackV2 is deprecated, prefer NewCallbackV3.
func NewCallbackV3 ¶ added in v0.248.0
func (Callback) DownstreamTimeoutContext ¶
func (Callback) HandleError ¶
func (Callback) MapError ¶ added in v0.58.0
MapError maps an error to an HTTPError in instances where custom error mapping is required. Return nil to perform default error mapping; defined as: 1. CustomError.HTTPError if the original error is a CustomError, otherwise 2. common.MapError.
func (Callback) WriteError ¶ added in v0.248.0
type CustomError ¶ added in v0.5.0
func (CustomError) Error ¶ added in v0.5.0
func (e CustomError) Error() string
type DownstreamError ¶
func (*DownstreamError) Error ¶
func (e *DownstreamError) Error() string
func (*DownstreamError) ErrorKind ¶
func (e *DownstreamError) ErrorKind() Kind
func (*DownstreamError) Unwrap ¶
func (e *DownstreamError) Unwrap() error
type ErrorKinder ¶
type ErrorKinder interface {
ErrorKind() Kind
}
type ErrorWriter ¶ added in v0.248.0
type ErrorWriter interface {
WriteError(ctx context.Context, w http.ResponseWriter) bool
}
If the error returned is an ErrorWriter the error handling will call the writeError method before any of the regular error handling (no mapping).
If the call returns true it means it wrote the error and will not do any more handling. If it returns false it will go through the normal error writing path (via both the MapError and WriteError callbacks).
type HTTPError ¶
type HTTPError struct { HTTPCode int `json:"-"` Code string `json:"code,omitempty"` Description string `json:"description,omitempty"` // contains filtered or unexported fields }
func (*HTTPError) WriteError ¶
func (httpError *HTTPError) WriteError(ctx context.Context, w http.ResponseWriter)
type InvalidHeaderError ¶ added in v0.258.0
type InvalidHeaderError struct {
// contains filtered or unexported fields
}
func (*InvalidHeaderError) CausedByParam ¶ added in v0.258.0
func (e *InvalidHeaderError) CausedByParam(param string) bool
func (*InvalidHeaderError) Error ¶ added in v0.258.0
func (e *InvalidHeaderError) Error() string
func (*InvalidHeaderError) GetCause ¶ added in v0.258.0
func (e *InvalidHeaderError) GetCause() error
This may be nil (for example if the cause was a regular expression mismatch) or may be InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise. You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors (there may be more than one).
type MockRoundTripper ¶
type RegexWithFallBack ¶ added in v0.258.0
type RegexWithFallBack struct {
// contains filtered or unexported fields
}
func RegexWithFallbackMustCompile ¶ added in v0.258.0
func RegexWithFallbackMustCompile(str string) *RegexWithFallBack
func (*RegexWithFallBack) MatchString ¶ added in v0.258.0
func (r *RegexWithFallBack) MatchString(s string) bool
type RestResult ¶ added in v0.69.0
func GetRestResult ¶ added in v0.69.0
func GetRestResult(ctx context.Context) *RestResult
GetRestResult gets the result of the most recent rest request. The context must be provisioned prior to the request taking place with a call to ProvisionRestResult.
type RestResultContextKey ¶ added in v0.69.0
type RestResultContextKey struct{}
type ServerError ¶
func (*ServerError) Error ¶
func (e *ServerError) Error() string
func (*ServerError) ErrorKind ¶
func (e *ServerError) ErrorKind() Kind
func (*ServerError) Unwrap ¶
func (e *ServerError) Unwrap() error
type ZeroHeaderLengthError ¶ added in v0.211.0
type ZeroHeaderLengthError struct {
// contains filtered or unexported fields
}
func (*ZeroHeaderLengthError) CausedByParam ¶ added in v0.211.0
func (e *ZeroHeaderLengthError) CausedByParam(param string) bool
func (*ZeroHeaderLengthError) Error ¶ added in v0.211.0
func (e *ZeroHeaderLengthError) Error() string