http

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultAliveCheck return always live.
	DefaultAliveCheck = func() AliveStatus { return Alive }
	// DefaultReadyCheck return always ready.
	DefaultReadyCheck = func() ReadyStatus { return Ready }
)

Functions

func MiddlewareChain added in v0.23.0

func MiddlewareChain(f http.Handler, mm ...MiddlewareFunc) http.Handler

MiddlewareChain chains middlewares to a handler func.

Types

type AliveCheckFunc added in v0.28.0

type AliveCheckFunc func() AliveStatus

AliveCheckFunc defines a function type for implementing a liveness check.

type AliveStatus added in v0.28.0

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 added in v0.31.0

type Builder struct {
	// contains filtered or unexported fields
}

Builder gathers all required and optional properties, in order to construct an HTTP component.

func NewBuilder added in v0.31.0

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) Create added in v0.31.0

func (cb *Builder) Create() (*Component, error)

Create constructs the HTTP component by applying the gathered properties.

func (*Builder) WithAliveCheckFunc added in v0.31.0

func (cb *Builder) WithAliveCheckFunc(acf AliveCheckFunc) *Builder

WithAliveCheckFunc sets the AliveCheckFunc used by the HTTP component.

func (*Builder) WithMiddlewares added in v0.31.0

func (cb *Builder) WithMiddlewares(mm ...MiddlewareFunc) *Builder

WithMiddlewares adds middlewares to the HTTP component.

func (*Builder) WithPort added in v0.31.0

func (cb *Builder) WithPort(p int) *Builder

WithPort sets the port used by the HTTP component.

func (*Builder) WithReadTimeout added in v0.31.0

func (cb *Builder) WithReadTimeout(rt time.Duration) *Builder

WithReadTimeout sets the Read Timeout for the HTTP component.

func (*Builder) WithReadyCheckFunc added in v0.31.0

func (cb *Builder) WithReadyCheckFunc(rcf ReadyCheckFunc) *Builder

WithReadyCheckFunc sets the ReadyCheckFunc used by the HTTP component.

func (*Builder) WithRoutesBuilder added in v0.32.0

func (cb *Builder) WithRoutesBuilder(rb *RoutesBuilder) *Builder

WithRoutesBuilder adds routes builder to the HTTP component.

func (*Builder) WithSSL added in v0.31.0

func (cb *Builder) WithSSL(c, k string) *Builder

WithSSL sets the filenames for the Certificate and Keyfile, in order to enable SSL.

func (*Builder) WithWriteTimeout added in v0.31.0

func (cb *Builder) WithWriteTimeout(wt time.Duration) *Builder

WithWriteTimeout sets the Write Timeout for the HTTP component.

type Component added in v0.2.0

type Component struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Component implementation of HTTP.

func (*Component) Run added in v0.2.0

func (c *Component) Run(ctx context.Context) error

Run starts the HTTP server.

type Error added in v0.23.0

type Error struct {
	// contains filtered or unexported fields
}

Error defines an abstract struct that can represent several types of HTTP errors.

func NewError added in v0.23.0

func NewError() *Error

NewError creates a new error with default Internal Server Error payload.

func NewErrorWithCodeAndPayload added in v0.23.0

func NewErrorWithCodeAndPayload(code int, payload interface{}) *Error

NewErrorWithCodeAndPayload creates a fully customizable error with the specified status code and payload.

func NewForbiddenError added in v0.23.0

func NewForbiddenError() *Error

NewForbiddenError creates a new forbidden error with default payload.

func NewForbiddenErrorWithPayload added in v0.23.0

func NewForbiddenErrorWithPayload(payload interface{}) *Error

NewForbiddenErrorWithPayload creates a new forbidden error with the specified payload.

func NewNotFoundError added in v0.23.0

func NewNotFoundError() *Error

NewNotFoundError creates a new not found error with default payload.

func NewNotFoundErrorWithPayload added in v0.23.0

func NewNotFoundErrorWithPayload(payload interface{}) *Error

NewNotFoundErrorWithPayload creates a new not found error with the specified payload.

func NewServiceUnavailableError added in v0.23.0

func NewServiceUnavailableError() *Error

NewServiceUnavailableError creates a new service unavailable error with default payload.

func NewServiceUnavailableErrorWithPayload added in v0.23.0

func NewServiceUnavailableErrorWithPayload(payload interface{}) *Error

NewServiceUnavailableErrorWithPayload creates a new service unavailable error with the specified payload.

func NewUnauthorizedError added in v0.23.0

func NewUnauthorizedError() *Error

NewUnauthorizedError creates a new validation error with default payload.

func NewUnauthorizedErrorWithPayload added in v0.23.0

func NewUnauthorizedErrorWithPayload(payload interface{}) *Error

NewUnauthorizedErrorWithPayload creates a new unauthorized error with the specified payload.

func NewValidationError added in v0.23.0

func NewValidationError() *Error

NewValidationError creates a new validation error with default payload.

func NewValidationErrorWithPayload added in v0.23.0

func NewValidationErrorWithPayload(payload interface{}) *Error

NewValidationErrorWithPayload creates a new validation error with the specified payload.

func (*Error) Error added in v0.23.0

func (e *Error) Error() string

Error returns the actual message of the error.

type MiddlewareFunc added in v0.23.0

type MiddlewareFunc func(next http.Handler) http.Handler

MiddlewareFunc type declaration of middleware func.

func NewAuthMiddleware added in v0.23.0

func NewAuthMiddleware(auth auth.Authenticator) MiddlewareFunc

NewAuthMiddleware creates a MiddlewareFunc that implements authentication using an Authenticator.

func NewLoggingTracingMiddleware added in v0.31.0

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 added in v0.23.0

func NewRecoveryMiddleware() MiddlewareFunc

NewRecoveryMiddleware creates a MiddlewareFunc that ensures recovery and no panic.

type ReadyCheckFunc added in v0.28.0

type ReadyCheckFunc func() ReadyStatus

ReadyCheckFunc defines a function type for implementing a readiness check.

type ReadyStatus added in v0.28.0

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 Route

type Route struct {
	// contains filtered or unexported fields
}

Route definition of a HTTP route.

type RouteBuilder added in v0.32.0

type RouteBuilder struct {
	// contains filtered or unexported fields
}

RouteBuilder for building a route.

func NewRawRouteBuilder added in v0.32.0

func NewRawRouteBuilder(path string, handler http.HandlerFunc) *RouteBuilder

NewRawRouteBuilder constructor.

func NewRouteBuilder added in v0.32.0

func NewRouteBuilder(path string, processor sync.ProcessorFunc) *RouteBuilder

NewRouteBuilder constructor.

func (*RouteBuilder) Build added in v0.32.0

func (rb *RouteBuilder) Build() (Route, error)

Build a route.

func (*RouteBuilder) MethodConnect added in v0.32.0

func (rb *RouteBuilder) MethodConnect() *RouteBuilder

MethodConnect HTTP method.

func (*RouteBuilder) MethodDelete added in v0.32.0

func (rb *RouteBuilder) MethodDelete() *RouteBuilder

MethodDelete HTTP method.

func (*RouteBuilder) MethodGet added in v0.32.0

func (rb *RouteBuilder) MethodGet() *RouteBuilder

MethodGet HTTP method.

func (*RouteBuilder) MethodHead added in v0.32.0

func (rb *RouteBuilder) MethodHead() *RouteBuilder

MethodHead HTTP method.

func (*RouteBuilder) MethodOptions added in v0.32.0

func (rb *RouteBuilder) MethodOptions() *RouteBuilder

MethodOptions HTTP method.

func (*RouteBuilder) MethodPatch added in v0.32.0

func (rb *RouteBuilder) MethodPatch() *RouteBuilder

MethodPatch HTTP method.

func (*RouteBuilder) MethodPost added in v0.32.0

func (rb *RouteBuilder) MethodPost() *RouteBuilder

MethodPost HTTP method.

func (*RouteBuilder) MethodPut added in v0.32.0

func (rb *RouteBuilder) MethodPut() *RouteBuilder

MethodPut HTTP method.

func (*RouteBuilder) MethodTrace added in v0.32.0

func (rb *RouteBuilder) MethodTrace() *RouteBuilder

MethodTrace HTTP method.

func (*RouteBuilder) WithAuth added in v0.32.0

func (rb *RouteBuilder) WithAuth(auth auth.Authenticator) *RouteBuilder

WithAuth adds authenticator.

func (*RouteBuilder) WithMiddlewares added in v0.32.0

func (rb *RouteBuilder) WithMiddlewares(mm ...MiddlewareFunc) *RouteBuilder

WithMiddlewares adds middlewares.

func (*RouteBuilder) WithTrace added in v0.32.0

func (rb *RouteBuilder) WithTrace() *RouteBuilder

WithTrace enables route tracing.

type RoutesBuilder added in v0.32.0

type RoutesBuilder struct {
	// contains filtered or unexported fields
}

RoutesBuilder creates a list of routes.

func NewRoutesBuilder added in v0.32.0

func NewRoutesBuilder() *RoutesBuilder

NewRoutesBuilder constructor.

func (*RoutesBuilder) Append added in v0.32.0

func (rb *RoutesBuilder) Append(builder *RouteBuilder) *RoutesBuilder

Append a route to the list.

func (*RoutesBuilder) Build added in v0.32.0

func (rb *RoutesBuilder) Build() ([]Route, error)

Build the routes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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