http

package
v0.74.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Apache-2.0 Imports: 18 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 = "GET /alive"
	// ReadyPath of the component.
	ReadyPath = "GET /ready"
)

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

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

type LivenessCheckFunc func() AliveStatus

LivenessCheckFunc defines a function type for implementing a liveness check.

type OptionFunc added in v0.74.0

type OptionFunc func(*Component) error

OptionFunc definition for configuring the component in a functional way.

func WithHandlerTimeout added in v0.74.0

func WithHandlerTimeout(wt time.Duration) OptionFunc

WithHandlerTimeout functional option.

func WithPort added in v0.74.0

func WithPort(port int) OptionFunc

WithPort functional option.

func WithReadTimeout added in v0.74.0

func WithReadTimeout(rt time.Duration) OptionFunc

WithReadTimeout functional option.

func WithShutdownGracePeriod added in v0.74.0

func WithShutdownGracePeriod(gp time.Duration) OptionFunc

WithShutdownGracePeriod functional option.

func WithTLS added in v0.74.0

func WithTLS(cert, key string) OptionFunc

WithTLS functional option.

func WithWriteTimeout added in v0.74.0

func WithWriteTimeout(wt time.Duration) OptionFunc

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

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

LivenessCheckRoute returns a route for liveness checks.

func LoggingRoutes added in v0.74.0

func LoggingRoutes() []*Route

LoggingRoutes returns a routes relates to logs.

func NewRoute added in v0.74.0

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

NewRoute creates a new raw route with functional configuration.

func ProfilingRoutes added in v0.74.0

func ProfilingRoutes(enableExpVar bool) []*Route

func ReadyCheckRoute added in v0.74.0

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

ReadyCheckRoute returns a route for ready checks.

func (Route) Handler added in v0.40.1

func (r Route) Handler() http.HandlerFunc

func (Route) Middlewares added in v0.40.1

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

func (Route) Path added in v0.40.1

func (r Route) Path() string

func (Route) String added in v0.74.0

func (r Route) String() string

type RouteOptionFunc added in v0.74.0

type RouteOptionFunc func(route *Route) error

RouteOptionFunc definition for configuring the route in a functional way.

func WithAuth added in v0.74.0

func WithAuth(auth auth.Authenticator) RouteOptionFunc

WithAuth option for setting the route auth.

func WithCache added in v0.74.0

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

WithCache option for setting the route cache.

func WithMiddlewares added in v0.74.0

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

WithMiddlewares option for setting the route optionFuncs.

func WithRateLimiting added in v0.74.0

func WithRateLimiting(limit float64, burst int) (RouteOptionFunc, error)

WithRateLimiting option for setting a route rate limiter.

type Routes added in v0.74.0

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

Routes definition.

func (*Routes) Append added in v0.74.0

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

Append route.

func (*Routes) Result added in v0.74.0

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

Result of the route aggregation.

Directories

Path Synopsis
Package auth provides abstractions for concrete implementations.
Package auth provides abstractions for concrete implementations.
apikey
Package apikey is a concrete implementation of the auth abstractions.
Package apikey is a concrete implementation of the auth abstractions.
Package cache provides a cache control and implementation components for http routes.
Package cache provides a cache control and implementation components for http routes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳