v2

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package v2 provides a ready to use HTTP component.

Index

Constants

View Source
const (
	// Alive represents a state defining an Alive state.
	Alive AliveStatus = 1
	// Unhealthy represents an unhealthy alive state.
	Unhealthy AliveStatus = 2

	// Ready represents a state defining a Ready state.
	Ready ReadyStatus = 1
	// NotReady represents a state defining a NotReady state.
	NotReady ReadyStatus = 2

	// AlivePath of the component.
	AlivePath = "/alive"
	// ReadyPath of the component.
	ReadyPath = "/ready"
)
View Source
const (
	// MetricsPath of the component.
	MetricsPath = "/metrics"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AliveStatus

type AliveStatus int

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

type Component

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

Component implementation of an HTTP router.

func New

func New(handler http.Handler, oo ...OptionFunc) (*Component, error)

New creates an HTTP component configurable by functional options.

func (*Component) Run

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

Run starts the HTTP server and returns only if listening and/or serving failed, or if the context was canceled.

type LivenessCheckFunc

type LivenessCheckFunc func() AliveStatus

LivenessCheckFunc defines a function type for implementing a liveness check.

type OptionFunc

type OptionFunc func(*Component) error

OptionFunc definition for configuring the component in a functional way.

func HandlerTimeout

func HandlerTimeout(wt time.Duration) OptionFunc

HandlerTimeout functional option.

func Port

func Port(port int) OptionFunc

Port functional option.

func ReadTimeout

func ReadTimeout(rt time.Duration) OptionFunc

ReadTimeout functional option.

func ShutdownGracePeriod

func ShutdownGracePeriod(gp time.Duration) OptionFunc

ShutdownGracePeriod functional option.

func TLS

func TLS(cert, key string) OptionFunc

TLS functional option.

func WriteTimeout

func WriteTimeout(wt time.Duration) OptionFunc

WriteTimeout functional option.

type ReadyCheckFunc

type ReadyCheckFunc func() ReadyStatus

ReadyCheckFunc defines a function type for implementing a readiness check.

type ReadyStatus

type ReadyStatus int

ReadyStatus type.

type Route

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

Route definition of an HTTP route.

func LivenessCheckRoute

func LivenessCheckRoute(acf LivenessCheckFunc) (*Route, error)

LivenessCheckRoute returns a route for liveness checks.

func MetricRoute

func MetricRoute() *Route

MetricRoute creation.

func NewConnectRoute

func NewConnectRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewConnectRoute constructor.

func NewDeleteRoute

func NewDeleteRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewDeleteRoute constructor.

func NewGetRoute

func NewGetRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewGetRoute constructor.

func NewHeadRoute

func NewHeadRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewHeadRoute constructor.

func NewOptionsRoute

func NewOptionsRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewOptionsRoute constructor.

func NewPatchRoute

func NewPatchRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewPatchRoute constructor.

func NewPostRoute

func NewPostRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewPostRoute constructor.

func NewPutRoute

func NewPutRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewPutRoute constructor.

func NewRoute

func NewRoute(method, path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewRoute creates a new raw route with functional configuration.

func NewTraceRoute

func NewTraceRoute(path string, handler http.HandlerFunc, oo ...RouteOptionFunc) (*Route, error)

NewTraceRoute constructor.

func ProfilingRoutes

func ProfilingRoutes(enableExpVar bool) []*Route

func ReadyCheckRoute

func ReadyCheckRoute(rcf ReadyCheckFunc) (*Route, error)

ReadyCheckRoute returns a route for ready checks.

func (Route) Handler

func (r Route) Handler() http.HandlerFunc

func (Route) Method

func (r Route) Method() string

func (Route) Middlewares

func (r Route) Middlewares() []patronhttp.Func

func (Route) Path

func (r Route) Path() string

func (Route) String

func (r Route) String() string

type RouteOptionFunc

type RouteOptionFunc func(route *Route) error

RouteOptionFunc definition for configuring the route in a functional way.

func Auth

Auth option for setting the route auth.

func Cache

func Cache(cache cache.TTLCache, ageBounds httpcache.Age) RouteOptionFunc

Cache option for setting the route cache.

func Middlewares

func Middlewares(mm ...patronhttp.Func) RouteOptionFunc

Middlewares option for setting the route optionFuncs.

func RateLimiting

func RateLimiting(limit float64, burst int) RouteOptionFunc

RateLimiting option for setting a route rate limiter.

type Routes

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

Routes definition.

func (*Routes) Append

func (r *Routes) Append(route *Route, err error)

Append route.

func (*Routes) Result

func (r *Routes) Result() ([]*Route, error)

Result of the route aggregation.

Directories

Path Synopsis
router

Jump to

Keyboard shortcuts

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