service

package
v0.2601.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package service provides service primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCleanupOnlyService added in v0.2202.0

func IsCleanupOnlyService(svc BackgroundService) bool

IsCleanupOnlyService checks whether a given service is a cleanup only service.

Types

type BackgroundService

type BackgroundService interface {
	CleanupAble

	// Name returns the service name.
	Name() string

	// Start starts the service.
	Start() error

	// Stop halts the service.
	Stop()

	// Quit returns a channel that will be closed when the service terminates.
	Quit() <-chan struct{}
}

BackgroundService is a background service.

func NewCleanupOnlyService

func NewCleanupOnlyService(svc CleanupAble, name string) BackgroundService

NewCleanupOnlyService wraps a service as a cleanup only service.

type BaseBackgroundService

type BaseBackgroundService struct {
	Logger *logging.Logger
	// contains filtered or unexported fields
}

BaseBackgroundService is a base implementation of BackgroundService.

func NewBaseBackgroundService

func NewBaseBackgroundService(name string) *BaseBackgroundService

NewBaseBackgroundService creates a new base background service implementation.

func (*BaseBackgroundService) Cleanup

func (b *BaseBackgroundService) Cleanup()

Cleanup performs the service specific post-termination cleanup.

func (*BaseBackgroundService) Name

func (b *BaseBackgroundService) Name() string

Name returns the service name.

func (*BaseBackgroundService) Quit

func (b *BaseBackgroundService) Quit() <-chan struct{}

Quit returns a channel that will be closed when the service terminates.

func (*BaseBackgroundService) Start

func (b *BaseBackgroundService) Start() error

Start starts the service.

func (*BaseBackgroundService) Stop

func (b *BaseBackgroundService) Stop()

Stop halts the service.

type CleanupAble

type CleanupAble interface {
	// Cleanup performs the service specific post-termination cleanup.
	Cleanup()
}

CleanupAble provides a Cleanup method.

func NewContextCleanup

func NewContextCleanup(parent context.Context) (context.Context, CleanupAble)

NewContextCleanup makes a context and a CleanupAble that cancels it.

type Group added in v0.2505.0

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

Group is responsible for concurrently starting a group of services.

func NewGroup added in v0.2505.0

func NewGroup(services ...Service) *Group

NewGroup creates a new service group with the given list of services.

func (*Group) Add added in v0.2505.0

func (g *Group) Add(services ...Service)

Add appends one or more services to the group.

func (*Group) Serve added in v0.2505.0

func (g *Group) Serve(ctx context.Context) error

Serve starts all services concurrently and blocks until they all complete, one returns an error, or the context is canceled.

type NamedService added in v0.2505.0

type NamedService interface {
	Service

	// Name returns the name of the service.
	Name() string
}

NamedService is a blocking service with an associated name.

type Service added in v0.2505.0

type Service interface {
	// Serve runs the service and blocks until it completes, an error occurs,
	// or the context is canceled.
	Serve(ctx context.Context) error
}

Service is a blocking service.

func AsBlocking added in v0.2506.0

func AsBlocking(service BackgroundService) Service

AsBlocking transforms a background service into a blocking service.

Jump to

Keyboard shortcuts

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