http

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultAliveCheck return always live.
	DefaultAliveCheck = func() AliveStatus { return Alive }
	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 Component added in v0.2.0

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

Component implementation of HTTP.

func New

func New(oo ...OptionFunc) (*Component, error)

New returns a new component.

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

func NewRecoveryMiddleware() MiddlewareFunc

NewRecoveryMiddleware creates a MiddlewareFunc that ensures recovery and no panic.

func NewTracingMiddleware added in v0.23.0

func NewTracingMiddleware(path string) MiddlewareFunc

NewTracingMiddleware creates a MiddlewareFunc that continues a tracing span and finishes it.

type OptionFunc added in v0.4.0

type OptionFunc func(*Component) error

OptionFunc defines a option func for the HTTP component.

func AliveCheck added in v0.28.0

func AliveCheck(acf AliveCheckFunc) OptionFunc

AliveCheck option for setting the liveness check function of the HTTP component.

func Middlewares added in v0.23.0

func Middlewares(mm ...MiddlewareFunc) OptionFunc

Middlewares option for setting the routes middlewares of the HTTP component.

func Port added in v0.2.0

func Port(port int) OptionFunc

Port option for setting the ports of the HTTP component.

func ReadyCheck added in v0.28.0

func ReadyCheck(rcf ReadyCheckFunc) OptionFunc

ReadyCheck option for setting the readiness check function of the HTTP component.

func Routes added in v0.2.0

func Routes(rr []Route) OptionFunc

Routes option for setting the routes of the HTTP component.

func Secure added in v0.4.2

func Secure(certFile, keyFile string) OptionFunc

Secure option for securing the default HTTP component.

func Timeouts added in v0.23.0

func Timeouts(read, write time.Duration) OptionFunc

Timeouts option for setting the timeouts of the HTTP component.

type ReadyCheckFunc added in v0.28.0

type ReadyCheckFunc func() ReadyStatus

AliveCheckFunc defines a function type for implementing a readiness check.

type ReadyStatus added in v0.28.0

type ReadyStatus int

AliveStatus type representing the liveness of the service via HTTP component.

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 {
	Pattern     string
	Method      string
	Handler     http.HandlerFunc
	Trace       bool
	Auth        auth.Authenticator
	Middlewares []MiddlewareFunc
}

Route definition of a HTTP route.

func NewAuthDeleteRoute added in v0.23.0

func NewAuthDeleteRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewAuthDeleteRoute creates a new DELETE route from a generic handler with auth capability.

func NewAuthGetRoute added in v0.23.0

func NewAuthGetRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewAuthGetRoute creates a new GET route from a generic handler with auth capability.

func NewAuthHeadRoute added in v0.23.0

func NewAuthHeadRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewAuthHeadRoute creates a new HEAD route from a generic handler with auth capability.

func NewAuthOptionsRoute added in v0.23.0

func NewAuthOptionsRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewAuthOptionsRoute creates a new OPTIONS route from a generic handler with auth capability.

func NewAuthPatchRoute added in v0.23.0

func NewAuthPatchRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewAuthPatchRoute creates a new PATCH route from a generic handler with auth capability.

func NewAuthPostRoute added in v0.23.0

func NewAuthPostRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewAuthPostRoute creates a new POST route from a generic handler with auth capability.

func NewAuthPutRoute added in v0.23.0

func NewAuthPutRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewAuthPutRoute creates a new PUT route from a generic handler with auth capability.

func NewAuthRouteRaw added in v0.23.0

func NewAuthRouteRaw(p string, m string, h http.HandlerFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewAuthRouteRaw creates a new route from a HTTP handler with auth capability.

func NewDeleteRoute added in v0.4.2

func NewDeleteRoute(p string, pr sync.ProcessorFunc, trace bool, mm ...MiddlewareFunc) Route

NewDeleteRoute creates a new DELETE route from a generic handler.

func NewGetRoute added in v0.4.2

func NewGetRoute(p string, pr sync.ProcessorFunc, trace bool, mm ...MiddlewareFunc) Route

NewGetRoute creates a new GET route from a generic handler.

func NewHeadRoute added in v0.23.0

func NewHeadRoute(p string, pr sync.ProcessorFunc, trace bool, mm ...MiddlewareFunc) Route

NewHeadRoute creates a new HEAD route from a generic handler.

func NewOptionsRoute added in v0.23.0

func NewOptionsRoute(p string, pr sync.ProcessorFunc, trace bool, mm ...MiddlewareFunc) Route

NewOptionsRoute creates a new OPTIONS route from a generic handler.

func NewPatchRoute added in v0.23.0

func NewPatchRoute(p string, pr sync.ProcessorFunc, trace bool, mm ...MiddlewareFunc) Route

NewPatchRoute creates a new PATCH route from a generic handler.

func NewPostRoute added in v0.4.2

func NewPostRoute(p string, pr sync.ProcessorFunc, trace bool, mm ...MiddlewareFunc) Route

NewPostRoute creates a new POST route from a generic handler.

func NewPutRoute added in v0.4.2

func NewPutRoute(p string, pr sync.ProcessorFunc, trace bool, mm ...MiddlewareFunc) Route

NewPutRoute creates a new PUT route from a generic handler.

func NewRoute

func NewRoute(p string, m string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator, mm ...MiddlewareFunc) Route

NewRoute creates a new route from a generic handler with auth capability.

func NewRouteRaw added in v0.2.0

func NewRouteRaw(p string, m string, h http.HandlerFunc, trace bool, mm ...MiddlewareFunc) Route

NewRouteRaw creates a new route from a HTTP handler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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