Documentation
¶
Index ¶
- type ListenerHTTP
- type Option
- func CorsAllowOrigins(origins ...string) Option[corsConfig]
- func HTTPServerIdleTimeout(t time.Duration) Option[timeoutsConfig]
- func HTTPServerReadHeaderTimeout(t time.Duration) Option[timeoutsConfig]
- func HTTPServerReadTimeout(t time.Duration) Option[timeoutsConfig]
- func HTTPServerWriteTimeout(t time.Duration) Option[timeoutsConfig]
- func HealthCheckAccessLog(enable bool) Option[healthConfig]
- func HealthCheckMetricsForEndpoint(enable bool) Option[healthConfig]
- func HealthCheckRoute(route string) Option[healthConfig]
- func HealthChecker(checker hc.HealthChecker) Option[healthConfig]
- func MetricsAccessLog(enable bool) Option[metricsConfig]
- func MetricsMetricsForEndpoint(enable bool) Option[metricsConfig]
- func MetricsRoute(route string) Option[metricsConfig]
- func WithCORS(options ...Option[corsConfig]) Option[config]
- func WithGlobalMiddlewares(middlewares ...midkit.Middleware) Option[config]
- func WithHTTPServerTimeouts(options ...Option[timeoutsConfig]) Option[config]
- func WithHealthCheck(options ...Option[healthConfig]) Option[config]
- func WithLogger(logger *slog.Logger) Option[config]
- func WithMetrics(options ...Option[metricsConfig]) Option[config]
- func WithProfiler(cfg pprofConfig) Option[config]
- func WithTLS(cert, key string) Option[config]
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) MountGroup ¶ added in v0.2.2
func (l *ListenerHTTP) MountGroup(route string, fn func(r chi.Router))
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 CorsAllowOrigins ¶ added in v0.2.5
CorsAllowOrigins adds origins to a lost of allowed origins for cors configuration.
func HTTPServerIdleTimeout ¶
HTTPServerIdleTimeout sets the http.Server IdleTimeout.
func HTTPServerReadHeaderTimeout ¶
HTTPServerReadHeaderTimeout sets the http.Server ReadHeaderTimeout.
func HTTPServerReadTimeout ¶
HTTPServerReadTimeout sets the http.Server ReadTimeout.
func HTTPServerWriteTimeout ¶
HTTPServerWriteTimeout sets the http.Server WriteTimeout.
func HealthCheckAccessLog ¶
HealthCheckAccessLog represents an optional function for WithHealthCheck function. If passed to the WithHealthCheck, will set the ServerSettings.health.accessLogsEnabled to true.
func HealthCheckMetricsForEndpoint ¶
HealthCheckMetricsForEndpoint represents an optional function for WithHealthCheck function. If passed to the WithHealthCheck, will set the ServerSettings.health.metricsForEndpointEnabled to true.
func HealthCheckRoute ¶
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 ¶
MetricsAccessLog represents an optional function for WithMetrics function. If passed to the WithMetrics, will set the ServerSettings.health.accessLogsEnabled to true.
func MetricsMetricsForEndpoint ¶
MetricsMetricsForEndpoint represents an optional function for WithMetrics function. If passed to the WithMetrics, will set the ServerSettings.health.metricsForEndpointEnabled to true.
func MetricsRoute ¶
MetricsRoute represents an optional function for WithMetrics function. If passed to the WithMetrics, will set the ServerSettings.health.route.
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 ¶
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 ¶
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 ¶
WithLogger sets the server logger.
func WithMetrics ¶
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.