server

package
v0.0.0-...-65f451a Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

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

type Factory interface {
	Create(options ...Option) *Server
}

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 ...

func (NoopLogger) InfoCtx

func (n NoopLogger) InfoCtx(ctx context.Context, msg string, keysAndValues ...interface{})

InfoCtx ...

func (NoopLogger) WarnCtx

func (n NoopLogger) WarnCtx(ctx context.Context, msg string, keysAndValues ...interface{})

WarnCtx ...

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

func WithServerConfig(c Config) Option

WithServerConfig provides an Option to provide a server configuration.

func WithServerLogger

func WithServerLogger(l Logger) Option

WithServerLogger provides an Option to provide a logger to be used by the Server

func WithServerPort

func WithServerPort(p int) Option

WithServerPort provides an Option to provide the port on which the Server listens. Defaults to 8080

func WithServerReadTimeout

func WithServerReadTimeout(t int) Option

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

func WithServerRouter(r Handler) Option

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

func WithServerWriteTimeout(t int) Option

WithServerWriteTimeout provides an Option to provide the maximum duration in milliseconds before timing out writes of the response. Defaults to 10 seconds

func WithShutdownDelaySeconds

func WithShutdownDelaySeconds(d int) Option

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

func WithSwaggerFile(f string) Option

WithSwaggerFile provides an Option to provide the swagger file location. Defaults to '/swagger.json'

type Router

type Router func() Handler

Router configures and provides a Handler

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.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve sets up a http server and begins listening

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is used to satisfy http.Handler interface, primarily to pass to test recorder.

Jump to

Keyboard shortcuts

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