server

package
v0.58.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIDefinition

type APIDefinition interface {
	Start(r router.Router) error
	Stop()
	Info() APIInfo
}

APIDefinition is used to control lifecycle of the API

func APIFunc

func APIFunc(start func(router.Router) error, stop func(), info APIInfo) APIDefinition

type APIInfo added in v0.40.1

type APIInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

APIInfo outlines the basic service information needed

type Config

type Config struct {
	HealthPath string `split_words:"true"`
	Port       int
	Host       string
	TLS        nconf.TLSConfig
}

type HealthChecker

type HealthChecker interface {
	Healthy(w http.ResponseWriter, r *http.Request) error
}

HealthChecker is used to run a custom health check Implement it on your API if you want it to be checked when the healthcheck is called

type Opt added in v0.51.1

type Opt func(s *http.Server)

Opt will allow modification of the http server

func WithAddress added in v0.51.1

func WithAddress(addr string) Opt

WithAddress will set the address field on the server

func WithHostAndPort added in v0.51.1

func WithHostAndPort(host string, port int) Opt

WithHostAndPort will use them in the form host:port as the address field on the server

func WithReadTimeout added in v0.51.1

func WithReadTimeout(dur time.Duration) Opt

WithReadTimeout will override the server's read timeout

func WithTLS added in v0.51.1

func WithTLS(cfg *tls.Config) Opt

WithTLS will use the provided TLS configuration

func WithWriteTimeout added in v0.51.1

func WithWriteTimeout(dur time.Duration) Opt

WithWriteTimeout will override the server's write timeout

type Server

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

Server handles the setup and shutdown of the http server for an API

func New

func New(log logrus.FieldLogger, config Config, api APIDefinition) (*Server, error)

New will build a server with the defaults in place

func NewOpts added in v0.51.1

func NewOpts(log logrus.FieldLogger, api APIDefinition, opts ...Opt) (*Server, error)

NewOpts will create the server with many defaults. You can use the opts to override them. the one major default you can't change by this is the health path. This is set to /health and be enabled.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) Shutdown

func (s *Server) Shutdown(to time.Duration) error

func (*Server) TestServer

func (s *Server) TestServer() *httptest.Server

Jump to

Keyboard shortcuts

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