server

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Service = dependency.Service{
	ConfigFunc: func(flags dependency.FlagSet) {
		flags.String("server-host", "0.0.0.0", "The IP to start on")
		flags.Int("server-port", 8080, "The port to start the web Server on")
		flags.Duration("read-timeout", 10*time.Second, "The read timeout for the HTTP Server")
		flags.Duration("read-header-timeout", 20*time.Second, "The read header timeout for the HTTP Server")
		flags.Duration("write-timeout", 20*time.Second, "The write timeout for the HTTP Server")
		flags.Duration("idle-timeout", 10*time.Second, "The idle timeout for the HTTP Server")
		flags.Int("max-header-bytes", http.DefaultMaxHeaderBytes, "The maximum size that the HTTP header can be in bytes")
	},
	Dependencies: fx.Provide(
		New,
	),
	InvokeFunc: Invoke,
	Constructor: func(server *http.Server) Server {
		return server
	},
}

Service allows the service to be used in the dependency builder nolint: gomnd

Functions

func Invoke

func Invoke(params Params)

Invoke is the function that is called to start the server

func New

func New(router http.Handler, getter dependency.ConfigGetter) *http.Server

New creates a new instance of the *http.Server configured by the config you decided

func StartServer

func StartServer(server Server, logger *zap.Logger) func(ctx context.Context) error

StartServer creates a closure that will start the server when called

func StopServer

func StopServer(server Server, logger *zap.Logger) func(ctx context.Context) error

StopServer creates a closure that will stop the server

Types

type Params

type Params struct {
	fx.In

	Lifecycle fx.Lifecycle
	Server    Server
	Logger    *zap.Logger
}

Params are the dependencies required to start the server

type Server

type Server interface {
	ListenAndServe() error
	Shutdown(ctx context.Context) error
}

Server is an interface that abstracts the *http.Server

Jump to

Keyboard shortcuts

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