Documentation ¶
Overview ¶
Package nethttp provides instrumentation for net/http.
Index ¶
- func AnnotateOpenAPI(s *openapi.Collector, setup ...func(op *openapi3.Operation) error) func(http.Handler) http.Handler
- func AnnotateOperation(annotations ...func(operation *openapi3.Operation) error) func(h *Handler)
- func HTTPBasicSecurityMiddleware(c *openapi.Collector, name, description string) func(http.Handler) http.Handler
- func HTTPBearerSecurityMiddleware(c *openapi.Collector, name, description, bearerFormat string) func(http.Handler) http.Handler
- func HandlerAs(handler http.Handler, target interface{}) bool
- func HandlerWithRouteMiddleware(method, pathPattern string) func(http.Handler) http.Handler
- func OpenAPIMiddleware(s *openapi.Collector) func(http.Handler) http.Handler
- func RequestMapping(v interface{}) func(h *Handler)
- func ResponseHeaderMapping(v interface{}) func(h *Handler)
- func SuccessStatus(status int) func(h *Handler)
- func SuccessfulResponseContentType(contentType string) func(h *Handler)
- func UseCaseMiddlewares(mw ...usecase.Middleware) func(http.Handler) http.Handler
- func WrapHandler(h http.Handler, mw ...func(http.Handler) http.Handler) http.Handler
- type Handler
- func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *Handler) SetRequestDecoder(requestDecoder RequestDecoder)
- func (h *Handler) SetResponseEncoder(responseEncoder ResponseEncoder)
- func (h *Handler) SetUseCase(useCase usecase.Interactor)
- func (h *Handler) UseCase() usecase.Interactor
- type RequestDecoder
- type ResponseEncoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnnotateOpenAPI ¶ added in v0.1.5
func AnnotateOpenAPI( s *openapi.Collector, setup ...func(op *openapi3.Operation) error, ) func(http.Handler) http.Handler
AnnotateOpenAPI applies OpenAPI annotation to relevant handlers.
func AnnotateOperation ¶
AnnotateOperation allows customizations of prepared operations.
func HTTPBasicSecurityMiddleware ¶
func HTTPBasicSecurityMiddleware(c *openapi.Collector, name, description string) func(http.Handler) http.Handler
HTTPBasicSecurityMiddleware creates middleware to expose Basic Security schema.
func HTTPBearerSecurityMiddleware ¶
func HTTPBearerSecurityMiddleware( c *openapi.Collector, name, description, bearerFormat string, ) func(http.Handler) http.Handler
HTTPBearerSecurityMiddleware creates middleware to expose HTTP Bearer security schema.
func HandlerAs ¶
HandlerAs finds the first http.Handler in http.Handler's chain that matches target, and if so, sets target to that http.Handler value and returns true.
An http.Handler matches target if the http.Handler's concrete value is assignable to the value pointed to by target.
HandlerAs will panic if target is not a non-nil pointer to either a type that implements http.Handler, or to any interface type.
func HandlerWithRouteMiddleware ¶
HandlerWithRouteMiddleware wraps handler with routing information.
func OpenAPIMiddleware ¶
OpenAPIMiddleware reads info and adds validation to handler.
func RequestMapping ¶
func RequestMapping(v interface{}) func(h *Handler)
RequestMapping creates rest.RequestMapping from struct tags.
This can be used to decouple mapping from usecase input with additional struct.
func ResponseHeaderMapping ¶
func ResponseHeaderMapping(v interface{}) func(h *Handler)
ResponseHeaderMapping creates headers mapping from struct tags.
This can be used to decouple mapping from usecase input with additional struct.
func SuccessStatus ¶
SuccessStatus sets status code of successful response.
func SuccessfulResponseContentType ¶
SuccessfulResponseContentType sets Content-Type of successful response.
func UseCaseMiddlewares ¶
UseCaseMiddlewares applies use case middlewares to Handler.
func WrapHandler ¶
WrapHandler wraps http.Handler with an unwrappable middleware.
Wrapping order is reversed, e.g. if you call WrapHandler(h, mw1, mw2, mw3) middlewares will be invoked in order of mw1(mw2(mw3(h))), mw3 first and mw1 last. So that request processing is first affected by mw1.
Types ¶
type Handler ¶
type Handler struct { rest.HandlerTrait // OperationAnnotations are called after operation setup and before adding operation to documentation. OperationAnnotations []func(op *openapi3.Operation) error // contains filtered or unexported fields }
Handler is a use case http handler with documentation and inputPort validation.
Please use NewHandler to create instance.
func NewHandler ¶
func NewHandler(useCase usecase.Interactor, options ...func(h *Handler)) *Handler
NewHandler creates use case http handler.
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves http inputPort with use case interactor.
func (*Handler) SetRequestDecoder ¶
func (h *Handler) SetRequestDecoder(requestDecoder RequestDecoder)
SetRequestDecoder sets request decoder.
func (*Handler) SetResponseEncoder ¶
func (h *Handler) SetResponseEncoder(responseEncoder ResponseEncoder)
SetResponseEncoder sets response encoder.
func (*Handler) SetUseCase ¶
func (h *Handler) SetUseCase(useCase usecase.Interactor)
SetUseCase prepares handler for a use case.
func (*Handler) UseCase ¶
func (h *Handler) UseCase() usecase.Interactor
UseCase returns use case interactor.
type RequestDecoder ¶
type RequestDecoder interface {
Decode(r *http.Request, input interface{}, validator rest.Validator) error
}
RequestDecoder maps data from http.Request into structured Go input value.
type ResponseEncoder ¶
type ResponseEncoder interface { WriteErrResponse(w http.ResponseWriter, r *http.Request, statusCode int, response interface{}) WriteSuccessfulResponse( w http.ResponseWriter, r *http.Request, output interface{}, ht rest.HandlerTrait, ) SetupOutput(output interface{}, ht *rest.HandlerTrait) MakeOutput(w http.ResponseWriter, ht rest.HandlerTrait) interface{} }
ResponseEncoder writes data from use case output/error into http.ResponseWriter.