httpgroup

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package httpgroup implements an errgroup for HTTP Servers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group is a variant of errgroup.Group on which workers are *http.Server/net.Listener instances

func (*Group) Cancel

func (heg *Group) Cancel() error

Cancel initiates a shutdown of all *http.Server{}s

func (*Group) Cancelled

func (heg *Group) Cancelled() bool

Cancelled tells if the Group has been cancelled

func (*Group) Count

func (heg *Group) Count() uint

Count returns how many servers are running in the Group

func (*Group) Go

func (heg *Group) Go(srv Server, lsn net.Listener) error

Go spawns a new Server controlled by the Group

func (*Group) SetContext

func (heg *Group) SetContext(ctx context.Context)

SetContext initialises a Group with a given and externally cancellable context.

func (*Group) SetLogger

func (heg *Group) SetLogger(logger slog.Logger)

SetLogger sets the slog.Logger to be used when supervising workers

func (*Group) Wait

func (heg *Group) Wait() error

Wait blocks until all servers have shut down

type Server

type Server interface {
	Serve(net.Listener) error
	Shutdown(context.Context) error
}

Server is a subset of the standard *http.Server including what httpgroup uses

type Worker

type Worker struct {
	Listener net.Listener
	Server   Server
}

Worker is an abstraction of a running Server

func (*Worker) IsError

func (*Worker) IsError(err error) bool

IsError filters out errors that can stop the Group

func (*Worker) Run

func (w *Worker) Run() error

Run is the blocking call that runs the Server

func (*Worker) Shutdown

func (w *Worker) Shutdown(ctx context.Context) error

Shutdown is the blocking call that stops a Server

Jump to

Keyboard shortcuts

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