api

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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

func AuthorizationHeader(next http.Handler) http.Handler

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

func InternalCommunication(token string, logger log.Logger) func(next http.Handler) http.Handler

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.

func (*LogErrorHandler) Handle

func (h *LogErrorHandler) Handle(_ context.Context, err error)

Handle implements go-kit ErrorHandler interface

type ServiceErrorer

type ServiceErrorer interface {
	ServiceError() *service.Error
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL