Documentation ¶
Index ¶
- Variables
- func ExtractParams(r *http.Request) map[string]string
- func MiddlewareChain(f http.Handler, mm ...MiddlewareFunc) http.Handler
- type AliveCheckFunc
- type AliveStatus
- type Builder
- func (cb *Builder) Create() (*Component, error)
- func (cb *Builder) WithAliveCheckFunc(acf AliveCheckFunc) *Builder
- func (cb *Builder) WithMiddlewares(mm ...MiddlewareFunc) *Builder
- func (cb *Builder) WithPort(p int) *Builder
- func (cb *Builder) WithReadTimeout(rt time.Duration) *Builder
- func (cb *Builder) WithReadyCheckFunc(rcf ReadyCheckFunc) *Builder
- func (cb *Builder) WithRoutesBuilder(rb *RoutesBuilder) *Builder
- func (cb *Builder) WithSSL(c, k string) *Builder
- func (cb *Builder) WithWriteTimeout(wt time.Duration) *Builder
- type Component
- type Error
- func NewError() *Error
- func NewErrorWithCodeAndPayload(code int, payload interface{}) *Error
- func NewForbiddenError() *Error
- func NewForbiddenErrorWithPayload(payload interface{}) *Error
- func NewNotFoundError() *Error
- func NewNotFoundErrorWithPayload(payload interface{}) *Error
- func NewServiceUnavailableError() *Error
- func NewServiceUnavailableErrorWithPayload(payload interface{}) *Error
- func NewUnauthorizedError() *Error
- func NewUnauthorizedErrorWithPayload(payload interface{}) *Error
- func NewValidationError() *Error
- func NewValidationErrorWithPayload(payload interface{}) *Error
- type MiddlewareFunc
- type ProcessorFunc
- type ReadyCheckFunc
- type ReadyStatus
- type Request
- type Response
- type Route
- type RouteBuilder
- func (rb *RouteBuilder) Build() (Route, error)
- func (rb *RouteBuilder) MethodConnect() *RouteBuilder
- func (rb *RouteBuilder) MethodDelete() *RouteBuilder
- func (rb *RouteBuilder) MethodGet() *RouteBuilder
- func (rb *RouteBuilder) MethodHead() *RouteBuilder
- func (rb *RouteBuilder) MethodOptions() *RouteBuilder
- func (rb *RouteBuilder) MethodPatch() *RouteBuilder
- func (rb *RouteBuilder) MethodPost() *RouteBuilder
- func (rb *RouteBuilder) MethodPut() *RouteBuilder
- func (rb *RouteBuilder) MethodTrace() *RouteBuilder
- func (rb *RouteBuilder) WithAuth(auth auth.Authenticator) *RouteBuilder
- func (rb *RouteBuilder) WithMiddlewares(mm ...MiddlewareFunc) *RouteBuilder
- func (rb *RouteBuilder) WithTrace() *RouteBuilder
- type RoutesBuilder
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultAliveCheck return always live. DefaultAliveCheck = func() AliveStatus { return Alive } // DefaultReadyCheck return always ready. DefaultReadyCheck = func() ReadyStatus { return Ready } )
Functions ¶
func ExtractParams ¶ added in v0.42.0
ExtractParams extracts dynamic URL parameters using httprouter's functionality
func MiddlewareChain ¶
func MiddlewareChain(f http.Handler, mm ...MiddlewareFunc) http.Handler
MiddlewareChain chains middlewares to a handler func.
Types ¶
type AliveCheckFunc ¶
type AliveCheckFunc func() AliveStatus
AliveCheckFunc defines a function type for implementing a liveness check.
type AliveStatus ¶
type AliveStatus int
AliveStatus type representing the liveness of the service via HTTP component.
const ( // Alive represents a state defining a Alive state. Alive AliveStatus = 1 // Unresponsive represents a state defining a Unresponsive state. Unresponsive AliveStatus = 2 )
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder gathers all required and optional properties, in order to construct an HTTP component.
func NewBuilder ¶
func NewBuilder() *Builder
NewBuilder initiates the HTTP component builder chain. The builder instantiates the component using default values for HTTP Port, Alive/Ready check functions and Read/Write timeouts.
func (*Builder) WithAliveCheckFunc ¶
func (cb *Builder) WithAliveCheckFunc(acf AliveCheckFunc) *Builder
WithAliveCheckFunc sets the AliveCheckFunc used by the HTTP component.
func (*Builder) WithMiddlewares ¶
func (cb *Builder) WithMiddlewares(mm ...MiddlewareFunc) *Builder
WithMiddlewares adds middlewares to the HTTP component.
func (*Builder) WithReadTimeout ¶
WithReadTimeout sets the Read Timeout for the HTTP component.
func (*Builder) WithReadyCheckFunc ¶
func (cb *Builder) WithReadyCheckFunc(rcf ReadyCheckFunc) *Builder
WithReadyCheckFunc sets the ReadyCheckFunc used by the HTTP component.
func (*Builder) WithRoutesBuilder ¶
func (cb *Builder) WithRoutesBuilder(rb *RoutesBuilder) *Builder
WithRoutesBuilder adds routes builder to the HTTP component.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error defines an abstract struct that can represent several types of HTTP errors.
func NewError ¶
func NewError() *Error
NewError creates a new error with default Internal Server Error payload.
func NewErrorWithCodeAndPayload ¶
NewErrorWithCodeAndPayload creates a fully customizable error with the specified status code and payload.
func NewForbiddenError ¶
func NewForbiddenError() *Error
NewForbiddenError creates a new forbidden error with default payload.
func NewForbiddenErrorWithPayload ¶
func NewForbiddenErrorWithPayload(payload interface{}) *Error
NewForbiddenErrorWithPayload creates a new forbidden error with the specified payload.
func NewNotFoundError ¶
func NewNotFoundError() *Error
NewNotFoundError creates a new not found error with default payload.
func NewNotFoundErrorWithPayload ¶
func NewNotFoundErrorWithPayload(payload interface{}) *Error
NewNotFoundErrorWithPayload creates a new not found error with the specified payload.
func NewServiceUnavailableError ¶
func NewServiceUnavailableError() *Error
NewServiceUnavailableError creates a new service unavailable error with default payload.
func NewServiceUnavailableErrorWithPayload ¶
func NewServiceUnavailableErrorWithPayload(payload interface{}) *Error
NewServiceUnavailableErrorWithPayload creates a new service unavailable error with the specified payload.
func NewUnauthorizedError ¶
func NewUnauthorizedError() *Error
NewUnauthorizedError creates a new validation error with default payload.
func NewUnauthorizedErrorWithPayload ¶
func NewUnauthorizedErrorWithPayload(payload interface{}) *Error
NewUnauthorizedErrorWithPayload creates a new unauthorized error with the specified payload.
func NewValidationError ¶
func NewValidationError() *Error
NewValidationError creates a new validation error with default payload.
func NewValidationErrorWithPayload ¶
func NewValidationErrorWithPayload(payload interface{}) *Error
NewValidationErrorWithPayload creates a new validation error with the specified payload.
type MiddlewareFunc ¶
MiddlewareFunc type declaration of middleware func.
func NewAuthMiddleware ¶
func NewAuthMiddleware(auth auth.Authenticator) MiddlewareFunc
NewAuthMiddleware creates a MiddlewareFunc that implements authentication using an Authenticator.
func NewLoggingTracingMiddleware ¶
func NewLoggingTracingMiddleware(path string) MiddlewareFunc
NewLoggingTracingMiddleware creates a MiddlewareFunc that continues a tracing span and finishes it. It also logs the HTTP request on debug logging level
func NewRecoveryMiddleware ¶
func NewRecoveryMiddleware() MiddlewareFunc
NewRecoveryMiddleware creates a MiddlewareFunc that ensures recovery and no panic.
type ProcessorFunc ¶
ProcessorFunc definition of a function type for processing sync requests.
type ReadyCheckFunc ¶
type ReadyCheckFunc func() ReadyStatus
ReadyCheckFunc defines a function type for implementing a readiness check.
type ReadyStatus ¶
type ReadyStatus int
ReadyStatus type.
const ( // Ready represents a state defining a Ready state. Ready ReadyStatus = 1 // NotReady represents a state defining a NotReady state. NotReady ReadyStatus = 2 )
type Request ¶
type Request struct { Fields map[string]string Raw io.Reader Headers map[string]string // contains filtered or unexported fields }
Request definition of the sync request model.
type Response ¶
type Response struct {
Payload interface{}
}
Response definition of the sync response model.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route definition of a HTTP route.
func (Route) Handler ¶ added in v0.40.1
func (r Route) Handler() http.HandlerFunc
Handler returns route handler function.
func (Route) Middlewares ¶ added in v0.40.1
func (r Route) Middlewares() []MiddlewareFunc
Middlewares returns route middlewares.
type RouteBuilder ¶
type RouteBuilder struct {
// contains filtered or unexported fields
}
RouteBuilder for building a route.
func NewRawRouteBuilder ¶
func NewRawRouteBuilder(path string, handler http.HandlerFunc) *RouteBuilder
NewRawRouteBuilder constructor.
func NewRouteBuilder ¶
func NewRouteBuilder(path string, processor ProcessorFunc) *RouteBuilder
NewRouteBuilder constructor.
func (*RouteBuilder) MethodConnect ¶
func (rb *RouteBuilder) MethodConnect() *RouteBuilder
MethodConnect HTTP method.
func (*RouteBuilder) MethodDelete ¶
func (rb *RouteBuilder) MethodDelete() *RouteBuilder
MethodDelete HTTP method.
func (*RouteBuilder) MethodGet ¶
func (rb *RouteBuilder) MethodGet() *RouteBuilder
MethodGet HTTP method.
func (*RouteBuilder) MethodHead ¶
func (rb *RouteBuilder) MethodHead() *RouteBuilder
MethodHead HTTP method.
func (*RouteBuilder) MethodOptions ¶
func (rb *RouteBuilder) MethodOptions() *RouteBuilder
MethodOptions HTTP method.
func (*RouteBuilder) MethodPatch ¶
func (rb *RouteBuilder) MethodPatch() *RouteBuilder
MethodPatch HTTP method.
func (*RouteBuilder) MethodPost ¶
func (rb *RouteBuilder) MethodPost() *RouteBuilder
MethodPost HTTP method.
func (*RouteBuilder) MethodPut ¶
func (rb *RouteBuilder) MethodPut() *RouteBuilder
MethodPut HTTP method.
func (*RouteBuilder) MethodTrace ¶
func (rb *RouteBuilder) MethodTrace() *RouteBuilder
MethodTrace HTTP method.
func (*RouteBuilder) WithAuth ¶
func (rb *RouteBuilder) WithAuth(auth auth.Authenticator) *RouteBuilder
WithAuth adds authenticator.
func (*RouteBuilder) WithMiddlewares ¶
func (rb *RouteBuilder) WithMiddlewares(mm ...MiddlewareFunc) *RouteBuilder
WithMiddlewares adds middlewares.
func (*RouteBuilder) WithTrace ¶
func (rb *RouteBuilder) WithTrace() *RouteBuilder
WithTrace enables route tracing.
type RoutesBuilder ¶
type RoutesBuilder struct {
// contains filtered or unexported fields
}
RoutesBuilder creates a list of routes.
func (*RoutesBuilder) Append ¶
func (rb *RoutesBuilder) Append(builder *RouteBuilder) *RoutesBuilder
Append a route to the list.