goserver

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 9 Imported by: 0

README

go-server

A go library to build a http server with safe shutdown

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultServer

func NewDefaultServer(config *Config, handler http.Handler) *http.Server

Types

type ApplyFunc

type ApplyFunc func(s *http.Server)

ApplyFunc is a function type that satisfies the options interface.

func SetAddr

func SetAddr(addr string) ApplyFunc

SetAddr sets the listening address for the server

func SetBaseContext

func SetBaseContext(ctx context.Context) ApplyFunc

SetBaseContext sets the basecontext for the server and currently ignores the net.Listener

func SetLogger

func SetLogger(logger *log.Logger) ApplyFunc

SetLogger sets the logger for the server

func SetTimeOuts

func SetTimeOuts(config *Config) ApplyFunc

SetTimeOuts sets the ReadTimeout, ReadHeaderTimeout, WriteTimeout, and IdleTimeout of the server from the provided config unset timeouts will default to 0 or No Timeout

func (ApplyFunc) Apply

func (a ApplyFunc) Apply(s *http.Server)

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Build

func (b *Builder) Build(ctx context.Context) *Server

func (*Builder) WithConfig

func (b *Builder) WithConfig(config *Config) *Builder

func (*Builder) WithContext

func (b *Builder) WithContext(ctx context.Context, cancel context.CancelFunc) *Builder

func (*Builder) WithCustomServer

func (b *Builder) WithCustomServer(server *http.Server) *Builder

func (*Builder) WithHandler

func (b *Builder) WithHandler(handler http.Handler) *Builder

func (*Builder) WithOptions

func (b *Builder) WithOptions(options ...Option) *Builder

type Config

type Config struct {
	Addr                string
	HealthCheckEndpoint string
	ReadTimeout         time.Duration
	ReadHeaderTimeout   time.Duration
	WriteTimeout        time.Duration
	IdleTimeout         time.Duration
}

func NewDefaultConfig

func NewDefaultConfig() *Config

type Option

type Option interface {
	Apply(s *http.Server)
}

Option is the interface to apply server options

type Options

type Options []Option

Options takes multiple options and applies them in one call

func (Options) Apply

func (o Options) Apply(s *http.Server)

type Server

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

func NewServer

func NewServer(server *http.Server, ctx context.Context, cancel context.CancelFunc) *Server

func (*Server) Start

func (s *Server) Start(waitFuncs ...WGFunc)

func (*Server) StartAndWait

func (s *Server) StartAndWait(waitFuncs ...WGFunc) error

func (*Server) Wait

func (s *Server) Wait() error

func (*Server) WatchContext

func (s *Server) WatchContext() WGFunc

WatchContext watches the provided context. When the context is Done, it will begin to shutdown the server and give time for other processes to finish.

func (*Server) WatchSignal

func (s *Server) WatchSignal(signals ...os.Signal) WGFunc

type WGFunc

type WGFunc func() error

Jump to

Keyboard shortcuts

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