httpkit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 ...midkit.Middleware)

func (*ListenerHTTP) Serve

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

type Option

type Option[T config | timeoutsConfig | healthConfig | metricsConfig | corsConfig | 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 WithCORS

func WithCORS(options ...Option[corsConfig]) Option[config]

WithCORS configures the CORS config for Houston API routes.

func WithGlobalMiddlewares

func WithGlobalMiddlewares(middlewares ...midkit.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