Back to

Package svc

Latest Go to latest

The latest major version is .

Published: Jun 22, 2020 | License: MIT | Module:



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 StartAndWait

func StartAndWait(ctx context.Context, svc Service) error

StartAndWait is helper for the initialization Start & Wait pattern

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

func LifecycleFnNoCtx

func LifecycleFnNoCtx(fn func() error) LifecycleFn

LifecycleFnNoCtx is a helper that turns a func() error into a LifecycleFn

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

Package Files

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

Jump to identifier

Keyboard shortcuts

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