httpkit

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProfilerMiddleware added in v0.2.7

func ProfilerMiddleware() http.Handler

Types

type ListenerHTTP

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

func NewListenerHTTP

func NewListenerHTTP(addr string, options ...Option[config]) (*ListenerHTTP, error)

NewListenerHTTP creates a new ListenerHTTP with the specified address and options. The options parameter is a variadic argument that accepts functions of type Option. The ListenerHTTP instance is returned, which can be used to mount routes and start serving requests.

func (*ListenerHTTP) Mount

func (l *ListenerHTTP) Mount(route string, handler http.Handler, middlewares ...Middleware)

func (*ListenerHTTP) MountGroup added in v0.2.2

func (l *ListenerHTTP) MountGroup(route string, fn func(r chi.Router))

func (*ListenerHTTP) Serve

func (l *ListenerHTTP) Serve(ctx context.Context) error

type Middleware added in v0.2.7

type Middleware = func(next http.Handler) http.Handler

Middleware represents a function type that serves as a middleware in an HTTP server. It takes the next http.Handler as a parameter and returns an http.Handler. The middleware function is responsible for intercepting and processing HTTP requests and responses.

func CORSMiddleware added in v0.2.7

func CORSMiddleware(o cors.Options) Middleware

func LoggingMiddleware added in v0.2.7

func LoggingMiddleware(logger *slog.Logger) Middleware

LoggingMiddleware represents logging middleware.

func MetricsMiddleware added in v0.2.7

func MetricsMiddleware() Middleware

MetricsMiddleware represents HTTP metrics collecting middlewares.

func RecoveryMiddleware added in v0.2.7

func RecoveryMiddleware() Middleware

func RedirectSlashesMiddleware added in v0.2.7

func RedirectSlashesMiddleware() Middleware

type Option

type Option[T config | timeoutsConfig | healthConfig | metricsConfig | pprofConfig] func(o *T)

Option implements functional options pattern for the ListenerHTTP type. Represents a function which receive a pointer to the generic struct that represents a part of ListenerHTTP configuration and changes it default values to the given ones.

See the applyOptionsHTTP function to understand the configuration behaviour. Option functions should only be passed to ListenerHTTP constructor function NewListenerHTTP.

func HTTPServerIdleTimeout

func HTTPServerIdleTimeout(t time.Duration) Option[timeoutsConfig]

HTTPServerIdleTimeout sets the http.Server IdleTimeout.

func HTTPServerReadHeaderTimeout

func HTTPServerReadHeaderTimeout(t time.Duration) Option[timeoutsConfig]

HTTPServerReadHeaderTimeout sets the http.Server ReadHeaderTimeout.

func HTTPServerReadTimeout

func HTTPServerReadTimeout(t time.Duration) Option[timeoutsConfig]

HTTPServerReadTimeout sets the http.Server ReadTimeout.

func HTTPServerWriteTimeout

func HTTPServerWriteTimeout(t time.Duration) Option[timeoutsConfig]

HTTPServerWriteTimeout sets the http.Server WriteTimeout.

func HealthCheckAccessLog

func HealthCheckAccessLog(enable bool) Option[healthConfig]

HealthCheckAccessLog represents an optional function for WithHealthCheck function. If passed to the WithHealthCheck, will set the ServerSettings.health.accessLogsEnabled to true.

func HealthCheckMetricsForEndpoint

func HealthCheckMetricsForEndpoint(enable bool) Option[healthConfig]

HealthCheckMetricsForEndpoint represents an optional function for WithHealthCheck function. If passed to the WithHealthCheck, will set the ServerSettings.health.metricsForEndpointEnabled to true.

func HealthCheckRoute

func HealthCheckRoute(route string) Option[healthConfig]

HealthCheckRoute represents an optional function for WithHealthCheck function. If passed to the WithHealthCheck, will set the ServerSettings.health.route.

func HealthChecker

func HealthChecker(checker hc.HealthChecker) Option[healthConfig]

HealthChecker represents an optional function for WithHealthCheck function. If passed to the WithHealthCheck, will set the ServerSettings.health.healthChecker.

func MetricsAccessLog

func MetricsAccessLog(enable bool) Option[metricsConfig]

MetricsAccessLog represents an optional function for WithMetrics function. If passed to the WithMetrics, will set the ServerSettings.health.accessLogsEnabled to true.

func MetricsMetricsForEndpoint

func MetricsMetricsForEndpoint(enable bool) Option[metricsConfig]

MetricsMetricsForEndpoint represents an optional function for WithMetrics function. If passed to the WithMetrics, will set the ServerSettings.health.metricsForEndpointEnabled to true.

func MetricsRoute

func MetricsRoute(route string) Option[metricsConfig]

MetricsRoute represents an optional function for WithMetrics function. If passed to the WithMetrics, will set the ServerSettings.health.route.

func WithGlobalMiddlewares

func WithGlobalMiddlewares(middlewares ...Middleware) Option[config]

WithGlobalMiddlewares sets given middlewares as router-wide middlewares. Means that they will be applied to each server endpoint.

func WithHTTPServerTimeouts

func WithHTTPServerTimeouts(options ...Option[timeoutsConfig]) Option[config]

WithHTTPServerTimeouts configures the HTTP listener timeoutsConfig. Receives the following option to configure the endpoint: - HTTPServerReadHeaderTimeout - sets the http.Server ReadHeaderTimeout. - HTTPServerReadTimeout - sets the http.Server ReadTimeout. - HTTPServerWriteTimeout - sets the http.Server WriteTimeout. - HTTPServerIdleTimeout - sets the http.Server IdleTimeout.

func WithHealthCheck

func WithHealthCheck(options ...Option[healthConfig]) Option[config]

WithHealthCheck turns on the health check endpoint. Receives the following option to configure the endpoint: - HealthChecker - to change the healthChecker implementation. - HealthCheckRoute - to set the endpoint route. - HealthCheckAccessLog - to enable access log for endpoint. - HealthCheckMetricsForEndpoint - to enable metrics collection for endpoint.

func WithLogger

func WithLogger(logger *slog.Logger) Option[config]

WithLogger sets the server logger.

func WithMetrics

func WithMetrics(options ...Option[metricsConfig]) Option[config]

WithMetrics turns on the metrics endpoint. Receives the following option to configure the endpoint: - MetricsRoute - to set the endpoint route. - MetricsAccessLog - to enable access log for endpoint. - MetricsMetricsForEndpoint - to enable metrics collection for endpoint.

func WithProfiler

func WithProfiler(cfg pprofConfig) Option[config]

WithProfiler turns on the profiler endpoint.

func WithTLS

func WithTLS(cert, key string) Option[config]

WithTLS sets the TLS certificate and key to be used by the HTTP server. The certificate and key must be provided as strings containing the file paths. Note that this function is an Option for config and should be passed to the NewServer constructor.

Jump to

Keyboard shortcuts

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