Documentation ¶
Index ¶
- type Config
- type Factory
- type FactoryOption
- type Handler
- type Logger
- type NoopLogger
- func (n NoopLogger) DPanicCtx(ctx context.Context, msg string, keysAndValues ...interface{})
- func (n NoopLogger) DebugCtx(ctx context.Context, msg string, keysAndValues ...interface{})
- func (n NoopLogger) ErrorCtx(ctx context.Context, msg string, keysAndValues ...interface{})
- func (n NoopLogger) InfoCtx(ctx context.Context, msg string, keysAndValues ...interface{})
- func (n NoopLogger) WarnCtx(ctx context.Context, msg string, keysAndValues ...interface{})
- type Option
- func WithHealthCheck(f func(http.HandlerFunc) http.HandlerFunc) Option
- func WithLivenessCheck(f func(http.HandlerFunc) http.HandlerFunc) Option
- func WithReadinessCheck(f func(http.HandlerFunc) http.HandlerFunc) Option
- func WithServerConfig(c Config) Option
- func WithServerLogger(l Logger) Option
- func WithServerPort(p int) Option
- func WithServerReadTimeout(t int) Option
- func WithServerRouter(r Handler) Option
- func WithServerTracer(t opentracing.Tracer) Option
- func WithServerWriteTimeout(t int) Option
- func WithShutdownDelaySeconds(d int) Option
- func WithSwaggerFile(f string) Option
- type Router
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Port *int ReadTimeoutMs *int WriteTimeoutMs *int RequestTimeoutSec *int ShutdownDelaySeconds *int SwaggerFile *string }
Config contains options for a Server
type Factory ¶
Factory is the interface to create Servers
func NewFactory ¶
func NewFactory(opts ...FactoryOption) Factory
NewFactory instantiates a Server Factory. FactoryOption can be passed to overwrite default configurations.
type FactoryOption ¶
type FactoryOption interface {
// contains filtered or unexported methods
}
FactoryOption interface to identify functional options
func WithConfig ¶
func WithConfig(c Config) FactoryOption
WithConfig provides an Option to provide a server configuration.
func WithLogger ¶
func WithLogger(l Logger) FactoryOption
WithLogger provides an option to provide a logger implementation. Defaults to Noop
func WithRouter ¶
func WithRouter(rf func() Handler) FactoryOption
WithRouter provides option to provide a function which returns which router will be used. Defaults to http.ServeMux
func WithTracer ¶
func WithTracer(t opentracing.Tracer) FactoryOption
WithTracer provides an Option to provide a tracer implementation. Defaults to Noop
type Handler ¶
type Handler interface { http.Handler HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) }
Handler is the interface to handle HTTP requests
type Logger ¶
type Logger interface { DebugCtx(ctx context.Context, msg string, keysAndValues ...interface{}) InfoCtx(ctx context.Context, msg string, keysAndValues ...interface{}) WarnCtx(ctx context.Context, msg string, keysAndValues ...interface{}) ErrorCtx(ctx context.Context, msg string, keysAndValues ...interface{}) }
Logger is a local interface for logging functionality
type NoopLogger ¶
type NoopLogger struct{}
NoopLogger is a noop logger implementation.
func (NoopLogger) DPanicCtx ¶
func (n NoopLogger) DPanicCtx(ctx context.Context, msg string, keysAndValues ...interface{})
DPanicCtx ...
func (NoopLogger) DebugCtx ¶
func (n NoopLogger) DebugCtx(ctx context.Context, msg string, keysAndValues ...interface{})
DebugCtx ...
func (NoopLogger) ErrorCtx ¶
func (n NoopLogger) ErrorCtx(ctx context.Context, msg string, keysAndValues ...interface{})
ErrorCtx ...
type Option ¶
type Option func(s *Server)
Option interface to identify functional options
func WithHealthCheck ¶
func WithHealthCheck(f func(http.HandlerFunc) http.HandlerFunc) Option
WithHealthCheck provides an Option to provide additional health checks that are performed on health check probe.
func WithLivenessCheck ¶
func WithLivenessCheck(f func(http.HandlerFunc) http.HandlerFunc) Option
WithLivenessCheck provides an Option to provide additional liveness checks that are performed on liveness probe.
func WithReadinessCheck ¶
func WithReadinessCheck(f func(http.HandlerFunc) http.HandlerFunc) Option
WithReadinessCheck provides an Option to provide additional readiness checks that are performed on readiness probe.
func WithServerConfig ¶
WithServerConfig provides an Option to provide a server configuration.
func WithServerLogger ¶
WithServerLogger provides an Option to provide a logger to be used by the Server
func WithServerPort ¶
WithServerPort provides an Option to provide the port on which the Server listens. Defaults to 8080
func WithServerReadTimeout ¶
WithServerReadTimeout provides an Option to provide the maximum duration in milliseconds for reading the entire request, including the body. Defaults to 10 seconds
func WithServerRouter ¶
WithServerRouter provides an Option to provide hooks to use the http request to mutate the request context.
func WithServerTracer ¶
func WithServerTracer(t opentracing.Tracer) Option
WithServerTracer provides an Option to provide a tracer to used by the Server
func WithServerWriteTimeout ¶
WithServerWriteTimeout provides an Option to provide the maximum duration in milliseconds before timing out writes of the response. Defaults to 10 seconds
func WithShutdownDelaySeconds ¶
WithShutdownDelaySeconds provides an Option to provide the duration by which server shutdown is delayed after receiving an os signal. Defaults to 5 seconds
func WithSwaggerFile ¶
WithSwaggerFile provides an Option to provide the swagger file location. Defaults to '/swagger.json'
type Server ¶
type Server struct { Router Handler // contains filtered or unexported fields }
Server represents a HTTP server. Server is instrumented with OpenTracing, logging, monitoring endpoints, and optionally an OpenAPI v2 endpoint.