server

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: MIT Imports: 21 Imported by: 1

Documentation

Overview

Package server provides the skeleton for goshop services

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BindConfig

type BindConfig struct {
	Interfaces []string `yaml:"interfaces"`
	Addresses  []string `yaml:"addresses" valid:"ip"`
}

BindConfig refers to the IP addresses used by a GoShop Server

type Config

type Config struct {
	Logger  slog.Logger     `yaml:"-" valid:",required"`
	Context context.Context `yaml:"-"`

	Name string `default:"nil.goshop.local" valid:"host,required"`

	Supervision SupervisionConfig `yaml:"run"`
	Addresses   BindConfig        `yaml:",omitempty"`
	TLS         TLSConfig
	HTTP        HTTPConfig
}

Config represents the generic configuration for goshop servers

func (*Config) New

func (cfg *Config) New() (*Server, error)

New creates a new server using the given config

func (*Config) SetDefaults

func (cfg *Config) SetDefaults() error

SetDefaults fills the gaps in the Config

func (*Config) Validate

func (cfg *Config) Validate() error

Validate tells if the configuration is worth a try

type HTTPConfig

type HTTPConfig struct {
	Port              uint16        `yaml:"port"                default:"8443" valid:"port"`
	InsecurePort      uint16        `yaml:"insecure-port"       default:"8080" valid:"port"`
	EnableInsecure    bool          `yaml:"enable-insecure"`
	MutualTLSOnly     bool          `yaml:"mtls-only"`
	ReadTimeout       time.Duration `yaml:"read-timeout"        default:"1s"`
	ReadHeaderTimeout time.Duration `yaml:"read-header-timeout" default:"2s"`
	WriteTimeout      time.Duration `yaml:"write-timeout"       default:"1s"`
	IdleTimeout       time.Duration `yaml:"idle-timeout"        default:"30s"`
}

HTTPConfig contains information for setting up the HTTP server

type Reloader

type Reloader interface {
	Reload() error
}

A Reloader is an application that can reload

type Server

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

A Server to run a node of a GoShop microservice

func New

func New(cfg *Config) (*Server, error)

New creates a new server using the given config

func (*Server) Cancel

func (srv *Server) Cancel()

Cancel initiates a shutdown of all workers

func (*Server) Cancelled

func (srv *Server) Cancelled() bool

Cancelled tells if the server has been cancelled

func (*Server) Err

func (srv *Server) Err() error

Err returns the reason of the shutdown, if any

func (*Server) Fail

func (srv *Server) Fail(err error)

Fail initiates a shutdown with a reason

func (*Server) Listen

func (srv *Server) Listen() error

Listen listens to all needed ports

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe(app http.Handler) error

ListenAndServe runs the Server

func (*Server) ListenWithListener

func (srv *Server) ListenWithListener(lc bind.TCPUDPListener) error

ListenWithListener listens to all needed ports using a net.ListenerConfig context

func (*Server) ListenWithUpgrader

func (srv *Server) ListenWithUpgrader(upg bind.Upgrader) error

ListenWithUpgrader listens to all needed ports using a ListenUpgrader like tableflip

func (*Server) Shutdown

func (srv *Server) Shutdown(timeout time.Duration) error

Shutdown initiates a Shutdown with optional fatal timeout, and waits until all workers are done

func (*Server) Spawn

func (srv *Server) Spawn(h http.Handler, healthy time.Duration) error

Spawn the workers

func (*Server) Wait

func (srv *Server) Wait() error

Wait blocks until all workers have exited

type SupervisionConfig

type SupervisionConfig struct {
	PIDFile         string        `yaml:"pid-file"         default:"/tmp/tableflip.pid"`
	GracefulTimeout time.Duration `yaml:"graceful-timeout" default:"5s"`
	HealthWait      time.Duration `yaml:"health-wait"      default:"1s"`
}

SupervisionConfig represents how graceful upgrades will operate

type TLSConfig

type TLSConfig struct {
	Key   string
	Cert  string
	Roots string
}

TLSConfig contains information for setting up TLS clients and server

func (*TLSConfig) Validate

func (c *TLSConfig) Validate() error

Validate tells if the configuration is worth a try

Directories

Path Synopsis
Package zerolog provides a zerolog based logger we use in our servers
Package zerolog provides a zerolog based logger we use in our servers

Jump to

Keyboard shortcuts

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