Documentation ¶
Index ¶
- Constants
- 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(logger *logrus.Logger) func(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.Entry
- func GetLoggerFromContext(ctx context.Context) *logrus.Logger
- 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.Context
- func NewBool(b bool) *bool
- func NewLoggingRoundTripper(name string, base http.RoundTripper) http.RoundTripper
- func NewString(s string) *string
- func NewTestCoreRequestContext() (*logrus.Logger, *test.Hook, context.Context)
- func NewTestCoreRequestContextWithLogger(logger *logrus.Logger) 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(ctx context.Context, timeout time.Duration, timeoutHandler http.Handler) func(next http.Handler) http.Handler
- func TimeoutHandler(ctx context.Context, h http.Handler, dt time.Duration, timeout http.Handler) http.Handler
- func TraceabilityMiddleware(logger *logrus.Logger) func(next http.Handler) http.Handler
- func TryGetTraceIDFromContext(ctx context.Context) (uuid.UUID, bool)
- func UpdateResponseStatus(ctx context.Context, status int) error
- type Callback
- func (g Callback) AddMiddleware(ctx context.Context, r chi.Router)
- func (g Callback) BasePath() string
- func (g Callback) Config() validator.Validator
- 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, ...)
- type Config
- type CustomError
- type DownstreamError
- type ErrorKinder
- type HTTPError
- type Kind
- type MockRoundTripper
- type SensitiveString
- func (s *SensitiveString) MarshalJSON() ([]byte, error)
- func (s SensitiveString) MarshalYAML() (interface{}, error)
- func (s SensitiveString) String() string
- func (s *SensitiveString) UnmarshalJSON(data []byte) error
- func (s *SensitiveString) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (s *SensitiveString) Value() string
- type ServerError
Constants ¶
const DefaultReplacementText = "****************"
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 HandleError ¶
func LoggerToContext ¶
func LoggerToContext(ctx context.Context, logger *logrus.Logger, entry *logrus.Entry) context.Context
LoggerToContext create a new context containing the logger
func NewLoggingRoundTripper ¶
func NewLoggingRoundTripper(name string, base http.RoundTripper) http.RoundTripper
func RequestHeaderFromContext ¶
RequestHeaderFromContext retrieve the request header from the context
func RequestHeaderToContext ¶
RequestHeaderToContext create a new context containing the request header
func RespHeaderAndStatusFromContext ¶
RespHeaderAndStatusFromContext retrieve response header and status from the context
func RespHeaderAndStatusToContext ¶
func RespHeaderAndStatusToContext(ctx context.Context, header http.Header, status int) context.Context
RespHeaderAndStatusToContext create a new context containing the response header and status
func Timeout ¶
func Timeout(ctx context.Context, 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 ¶
func TimeoutHandler(ctx context.Context, h http.Handler, dt time.Duration, timeout http.Handler) http.Handler
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 buffers all Handler writes to memory and does not support the Hijacker or Flusher interfaces.
func TraceabilityMiddleware ¶
Injects a traceId UUID into the request context
Types ¶
type Callback ¶
type Callback struct { UpstreamTimeout time.Duration DownstreamTimeout time.Duration RouterBasePath string UpstreamConfig validator.Validator }
func DefaultCallback ¶
func DefaultCallback() Callback
func (Callback) DownstreamTimeoutContext ¶
func (Callback) HandleError ¶
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 HTTPError ¶
type HTTPError struct { HTTPCode int `json:"-"` Code string `json:"code,omitempty"` Description string `json:"description,omitempty"` }
func (*HTTPError) WriteError ¶
func (httpError *HTTPError) WriteError(ctx context.Context, w http.ResponseWriter)
type MockRoundTripper ¶
type SensitiveString ¶
type SensitiveString struct {
// contains filtered or unexported fields
}
func NewSensitiveString ¶
func NewSensitiveString(from string) SensitiveString
func (*SensitiveString) MarshalJSON ¶
func (s *SensitiveString) MarshalJSON() ([]byte, error)
func (SensitiveString) MarshalYAML ¶
func (s SensitiveString) MarshalYAML() (interface{}, error)
Note, this one needs to be an object receiver NOT a pointer receiver
func (SensitiveString) String ¶
func (s SensitiveString) String() string
func (*SensitiveString) UnmarshalJSON ¶
func (s *SensitiveString) UnmarshalJSON(data []byte) error
func (*SensitiveString) UnmarshalYAML ¶
func (s *SensitiveString) UnmarshalYAML(unmarshal func(interface{}) error) error
func (*SensitiveString) Value ¶
func (s *SensitiveString) Value() string
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