Documentation ¶
Overview ¶
Package endpoint provides helpers and additional functionality for github.com/go-kit/kit/endpoint .
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyMiddlewares ¶
Applies zero or more middlewares to an endpoint. Middlewares are applied in order, i.e. first middleware passed is applied first and therefore innermost, last middleware passed is outermost.
func ErrorLoggingMiddleware ¶
func ErrorLoggingMiddleware(logger log.Logger) endpoint.Middleware
Logs errors contained in the endpoint response, if the response type implements the Responder interface. Errors from endpoint code should be caught/logged with transport level error handlers (see e.g. the errorHandler option to github.com/go-kit/kit/transport/http.NewServer).
func InstrumentRequestTimeMiddleware ¶
func InstrumentRequestTimeMiddleware(duration metrics.Histogram) endpoint.Middleware
Endpoint middleware that records to the given histrogram the time it takes the endpoint to process requests.
Types ¶
type Responder ¶
type Responder interface { Response() interface{} Error() error }
A type implementing Responder can be used to wrap a result and error value returned by the business logic/service/component part of an endpoint. This makes it easier to distinguish between errors originating in business logic/service/component code of an endpoint and errors originating in endpoint code itself, e.g. an endpoint middleware. An error from the business logic/service/component code will be wrapped in the Responder type and therefore returned as part of the "response" (first) return value of an endpoint function. Whereas an error from endpoint code will be returned as the error return value of an endpoint function.
The following examples demonstrate the intended usage of Responder:
func endpointFunc(ctx context.Context, request interface{}) (interface{}, error) { result, err := service.SomeServiceMethod(ctx, request) // Wrap error from service in Response, the default type implementing Responder. // The error return value of this endpoint function will be nil. return Response{ R: result, Err: err, }, nil } // Errors from an endpoint middleware will be returned in the error return value of the endpoint function. func exampleEndpointMiddleware() endpoint.Middleware { return func(next endpoint.Endpoint) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (interface{}, error) { err := PerformSomeOperationThatMightFail(request) if err != nil { return nil, err } return next(ctx, request) } } }