Help us shape the future of Go! Take the 2026 Go Developer Survey

service

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package service defines a unified lifecycle interface for application services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HealthChecker

type HealthChecker interface {
	// Health returns nil when the service is healthy.
	Health(ctx context.Context) error
}

HealthChecker is an optional interface that services can implement to participate in health checks.

type Registry

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

Registry manages service registration, startup, and shutdown.

func NewRegistry

func NewRegistry(logger *zap.Logger) *Registry

NewRegistry creates a new service registry.

func (*Registry) HealthChecks

func (r *Registry) HealthChecks() []HealthChecker

HealthChecks returns all registered services that implement HealthChecker.

func (*Registry) Register

func (r *Registry) Register(svc Service, info ServiceInfo)

Register adds a service to the registry.

func (*Registry) StartAll

func (r *Registry) StartAll(ctx context.Context) error

StartAll starts all registered services in dependency/priority order. If any service fails to start, already-started services are stopped in reverse order.

func (*Registry) StopAll

func (r *Registry) StopAll(ctx context.Context) error

StopAll stops all started services in reverse startup order. Each service Stop call has a 10-second timeout.

type Service

type Service interface {
	// Name returns the service name (used for logging and dependency resolution).
	Name() string
	// Start initializes and starts the service.
	Start(ctx context.Context) error
	// Stop gracefully shuts down the service.
	Stop(ctx context.Context) error
}

Service defines the unified service lifecycle interface.

type ServiceInfo

type ServiceInfo struct {
	// Name identifies the service (must match Service.Name()).
	Name string
	// Priority controls startup order (lower numbers start first).
	Priority int
	// DependsOn lists service names that must be started before this one.
	DependsOn []string
}

ServiceInfo holds metadata for service registration.

Jump to

Keyboard shortcuts

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