bootstrap

package
v0.0.0-...-34c5bf1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 23 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Revision string

Revision is the service's revision and should be set at build time to the current git commit hash.

Functions

func SetupTest

func SetupTest()

SetupTest should be called in a TestMain() function to setup the various global state that code relies on.

Types

type Opts

type Opts struct {
	// Config is a pointer to a struct which, if not nil, will
	// be populated with config from environment variables.
	Config interface{}

	// ServiceName is the name of the service e.g. service.foo
	ServiceName string
}

Opts defines basic initialisation options for a service

type Process

type Process interface {
	// GetName returns a friendly name for the process for use in logs
	GetName() string

	// Start kicks off the task and only returns when the task has finished.
	// The task will be stopped if the context is cancelled.
	Start(ctx context.Context) error
}

Process is a long-running task that provides service functionality

type Service

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

Service represents a collection of processes

func Init

func Init(opts *Opts) *Service

Init performs standard service startup tasks and returns a Service

func (*Service) Database

func (s *Service) Database() database.Database

Database is a helper function that returns a cached database. The first time it is called, a new connection to the database is established. Closing the connection when the program ends is handled automatically.

func (*Service) FirehosePublisher

func (s *Service) FirehosePublisher() firehose.Publisher

FirehosePublisher is a helper function that returns a cached firehose client. The first time it is called, a new firehose client is set up.

func (*Service) HandleFunc

func (s *Service) HandleFunc(method, path string, handler func(context.Context, taxi.Decoder) (interface{}, error))

HandleFunc registers a new taxi-style handler with the application's router for the specified method and path.

func (*Service) HandleRaw

func (s *Service) HandleRaw(method, path string, handler http.Handler)

HandleRaw registers a new http.Handler with the application's router for the specified method and path.

func (*Service) Health

func (s *Service) Health(ctx context.Context) map[string]error

Health returns a map representing the result of all of the health checks that have been registered.

func (*Service) Hostname

func (s *Service) Hostname() string

Hostname returns the hostname as reported by the operating system's kernel.

func (*Service) Revision

func (s *Service) Revision() string

Revision returns the current revision of the code.

func (*Service) Run

func (s *Service) Run(processes ...Process)

Run starts all processes that have already been registered with the service, plus any extra ones passed in as arguments. This function blocks until either all processes return, or an interrupt signal is received, at which point all processes are signalled to end. If any processes do not, at this point, return, then Run() may hang indefinitely.

Jump to

Keyboard shortcuts

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