Documentation ¶
Index ¶
- Constants
- func AuthorizationHeader(next http.Handler) http.Handler
- func EncodeError(ctx context.Context, err error, w http.ResponseWriter)
- func EncodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error
- func InternalCommunication(token string, logger log.Logger) func(next http.Handler) http.Handler
- func NewLogErrorHandler(logger log.Logger) transport.ErrorHandler
- func NewMethodNotAllowedHandler(logger log.Logger) http.HandlerFunc
- func NewNotFoundHandler(logger log.Logger) http.HandlerFunc
- type ErrResponse
- type LogErrorHandler
- type ServiceErrorer
Constants ¶
const ( // AuthorizationHeaderKey is the value used to place // the authorization header content in context.Context. AuthorizationHeaderKey authenticatorKey = iota )
Variables ¶
This section is empty.
Functions ¶
func AuthorizationHeader ¶
AuthorizationHeader tries to retrieve the token string from the "Authorization" request header and adds it to the context.
func EncodeError ¶
func EncodeError(ctx context.Context, err error, w http.ResponseWriter)
EncodeError encodes errors occurred on transport layer
func EncodeResponse ¶
func EncodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error
EncodeResponse is a default response encoder. It uses go-kit JSON Encoder. If response implements ServiceErrorer interface and response.ServiceError() is not nil, then it's handled as ErrResponse.
func InternalCommunication ¶
InternalCommunication performs bearer authentication with provided token for internal service communication purposes.
func NewLogErrorHandler ¶
func NewLogErrorHandler(logger log.Logger) transport.ErrorHandler
NewLogErrorHandler returns a new log middleware for go-kit transport
func NewMethodNotAllowedHandler ¶
func NewMethodNotAllowedHandler(logger log.Logger) http.HandlerFunc
NewMethodNotAllowedHandler returns http.HandlerFunc, that handles default 405 behavior
func NewNotFoundHandler ¶
func NewNotFoundHandler(logger log.Logger) http.HandlerFunc
NewNotFoundHandler returns http.HandlerFunc, that handles default 404 behavior
Types ¶
type ErrResponse ¶
type ErrResponse struct { Error string `json:"error,omitempty"` // contains filtered or unexported fields }
ErrResponse renderer type for handling all sorts of business errors.
func ErrBadRequest ¶
func ErrBadRequest(err error) *ErrResponse
ErrBadRequest handler returns the pre-defined 400 schema.
func ErrForbidden ¶
func ErrForbidden() *ErrResponse
ErrForbidden handler returns the pre-defined 403 schema.
func ErrInternal ¶
func ErrInternal(err error) *ErrResponse
ErrInternal handler returns the pre-defined 500 schema.
func ErrMethodNotAllowed ¶
func ErrMethodNotAllowed(err error) *ErrResponse
ErrMethodNotAllowed handler returns the pre-defined 405 schema.
func ErrNotFound ¶
func ErrNotFound(err error) *ErrResponse
ErrNotFound handler returns the pre-defined 404 schema.
func ErrUnauthorized ¶
func ErrUnauthorized() *ErrResponse
ErrUnauthorized handler returns the pre-defined 401 schema.
func NewErrResponse ¶
func NewErrResponse(err *service.Error) *ErrResponse
NewErrResponse wraps Error into HTTP error response
func (*ErrResponse) StatusCode ¶
func (e *ErrResponse) StatusCode() int
StatusCode returns an HTTP status code. It implements kithttp.StatusCoder interface
type LogErrorHandler ¶
type LogErrorHandler struct {
// contains filtered or unexported fields
}
LogErrorHandler is a transport error handler implementation which logs an error.
type ServiceErrorer ¶
ServiceErrorer is used to pass business-logic errors through service -> endpoint -> transport layers. If the endpoint can return a business-logic error, then you need to implement the ServiceError() method.