server

package
v0.0.0-...-3e16b6b Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: MIT Imports: 10 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
}

type Factory

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

Factory interface to create a server.

func NewFactory

func NewFactory(options ...FactoryOption) Factory

NewFactory instantiates a new server Factory

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 option to provide a server configuration.

func WithLogger

func WithLogger(l Logger) FactoryOption

WithLogger provides option to provide a logger implementation. Noop is default

func WithRouter

func WithRouter(rf func() Handler) FactoryOption

WithRouter provides option to provide a function which returns which router will be used. By default we use http.ServeMux

func WithTracer

func WithTracer(t opentracing.Tracer) FactoryOption

WithTracer provides option to provide a tracer implementation. Noop is default

type Handler

type Handler interface {
	http.Handler
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}

type Logger

type Logger interface {
	Debug(ctx context.Context, msg string, keysAndValues ...interface{})
	Error(ctx context.Context, msg string, keysAndValues ...interface{})
	Info(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) DPanic

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

DPanic ...

func (NoopLogger) Debug

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

Debug ...

func (NoopLogger) Error

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

Error ...

func (NoopLogger) Info

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

Info ...

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option interface to identify functional options

func WithHealthCheck

func WithHealthCheck(f func(http.HandlerFunc) http.HandlerFunc) Option

WithHealthCheck provides 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 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 option to provide additional readiness checks that are performed on readiness probe.

func WithServerConfig

func WithServerConfig(c Config) Option

WithServerConfig provides option to provide a server configuration.

func WithServerLogger

func WithServerLogger(l Logger) Option

WithServerLogger provides option to provide a logger to use while writing.

func WithServerPort

func WithServerPort(p int) Option

WithServerPort provides option to provide the port on which the server listens. Default is 80

func WithServerReadTimeout

func WithServerReadTimeout(t int) Option

WithServerReadTimeout provides 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 option to provide hooks to use the http request to mutate the request context.

func WithServerTracer

func WithServerTracer(t opentracing.Tracer) Option

WithServerTracer provides option to provide a tracer to use while writing.

func WithServerWriteTimeout

func WithServerWriteTimeout(t int) Option

WithServerWriteTimeout provides 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 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 option to provide the swagger file location. Default is '/swagger.json'

type Server

type Server struct {
	Router Handler
	// contains filtered or unexported fields
}

Server represents a http server

func (*Server) Serve

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

Serve sets up a http server and starts listening

func (*Server) ServeHTTP

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

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