Back to

Package servicestuff

v0.0.0 (7f9159c)
Latest Go to latest
Published: Feb 27, 2020 | License: MIT | Module:


Package Files


const (
	StateEmpty   = "empty"
	StateStarted = "started"
	StateStopped = "stopped"

Valid state values


var (
	ErrStartInvalid = errors.New("Attempting to start a service that has already been started")
	ErrStopInvalid  = errors.New("Attempting to stop a service that is not running")
	ErrWaitInvalid  = errors.New("Attempting to wait on a service that is not running")


func Start

func Start(ctx context.Context, svcs ...Service) error

Start starts multiple services

func Stop

func Stop(ctx context.Context, svcs ...Service) error

Stop stops multiple services

func Wait

func Wait(ctx context.Context, svcs ...Service) error

Wait waits on multiple services

type LifecycleFn

type LifecycleFn func(context.Context) error

LifecycleFn is a helper type for describing the start, stop, wait methods

type Service

type Service interface {
	Start(context.Context) error
	Stop(context.Context) error
	Wait(context.Context) error

A Service is a long running process that can start, stop and wait.

func Multi

func Multi(svcs ...Service) Service

Multi returns a new Service that provides a unified Service interface for all of the provided services

func WrapBlocking

func WrapBlocking(start LifecycleFn, stop LifecycleFn) Service

WrapBlocking transforms a blocking start func (like http.ListenAndServe) and returns a Service

func WrapStartStop

func WrapStartStop(start LifecycleFn, stop LifecycleFn) Service

WrapStartStop wraps a start function that returns immediately and returns a Service

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier