service

package
v0.5.14 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 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 Server added in v0.3.0

type Server interface {
	// Start Starts the server. The method also returns an error immediately if
	// the server fails to start. The server runs until the provided context is
	// cancelled.
	//
	// If an exitErr channel is given, then the server writes an error or nil
	// to the channel when it exits. This channel should be buffered so that
	// every service writing to it perform one non-blocking write.
	Start(ctx context.Context, exitErr chan<- error) 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