service

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoService = errors.New("no service is running")

Functions

func StartServers added in v0.3.0

func StartServers(ctx context.Context, logger *log.ZapEventLogger, servers ...Server) error

StartServers is responsible for starting the provided servers concurrently and managing their lifecycle events such as interrupts or failures. The function will ensure that if any server fails or if there is an external interrupt, all servers will be gracefully shut down.

Parameters:

  • ctx: Context that allows for asynchronous task cancellation.
  • logger: A pointer to a logging instance of type *log.ZapEventLogger.
  • servers: A variadic parameter that lists all the server instances that need to be started.

Returns:

  • error: The error encountered during the operation, if any.

The function uses channels to listen for events like server failure or external interrupts (like Ctrl+C) and ensures all servers are gracefully terminated before exiting.

Types

type Done added in v0.3.0

type Done = <-chan struct{}

type Fail added in v0.3.0

type Fail = <-chan error

type Server added in v0.3.0

type Server interface {
	// Start Starts the server and returns two channels. The Done channels are closed when the server is done running,
	//	and the Fail channel receives an error if the server fails. The method also returns an error immediately
	//	if the server fails to start. The server runs until the provided context is cancelled.
	Start(ctx context.Context) ([]Done, Fail, error)
	// Name returns the name of the server.
	Name() string
}

Server is an interface that represents a server that can be started and has a name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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