service

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

Public API (Governor)

  • Register(name, svc) — add service.
  • SetEnabled(name, on) — desired toggle.
  • SetInstances(name, n) — desired instances (if Scalable).
  • Start() / Stop(ctx) — run convergence loop / graceful stop.
  • Reload(ctx, name, cfg) — forward config to a service.
  • ServiceNames() []string — list of registered services.
  • ServiceState(name) (ServiceState, ok) — detailed snapshot for a service.
  • Metrics() Metrics — governor-level metrics snapshot.

Testing

go test ./pkg/service -race -v

Documentation

Overview

Package service defines the Service contract and a production-grade Governor. RACE-SAFE: per-service state is tracked with atomics; SetEnabled never calls svc directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Governor

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

func NewGovernor

func NewGovernor(checkInterval time.Duration) *Governor

func (*Governor) ActiveServicesCount

func (g *Governor) ActiveServicesCount() int

func (*Governor) Logs

func (g *Governor) Logs() <-chan ServiceLog

func (*Governor) Metrics

func (g *Governor) Metrics() Metrics

func (*Governor) Register

func (g *Governor) Register(name string, s Service)

func (*Governor) Reload

func (g *Governor) Reload(ctx context.Context, name string, cfg any) error

func (*Governor) ServiceNames

func (g *Governor) ServiceNames() []string

func (*Governor) ServiceState

func (g *Governor) ServiceState(name string) (ServiceState, bool)

func (*Governor) ServicesCount

func (g *Governor) ServicesCount() int

Convenience counters

func (*Governor) SetEnabled

func (g *Governor) SetEnabled(name string, enabled bool) error

func (*Governor) SetInstances

func (g *Governor) SetInstances(name string, n int) error

func (*Governor) Start

func (g *Governor) Start()

func (*Governor) Stop

func (g *Governor) Stop(ctx context.Context) error

func (*Governor) TotalInstances

func (g *Governor) TotalInstances() int

type Level

type Level string
const (
	Debug Level = "debug"
	Info  Level = "info"
	Warn  Level = "warn"
	Error Level = "error"
)

type Metrics

type Metrics map[string]float64

type Scalable

type Scalable interface {
	ScaleTo(n int) error
	Instances() int
}

type Service

type Service interface {
	IsActive() bool
	Launch(ctx context.Context) error
	Stop(ctx context.Context) error
	Reload(ctx context.Context, cfg any) error
	Off()
	On()
	Metrics() Metrics
	Logs() <-chan ServiceLog
}

type ServiceLog

type ServiceLog struct {
	Time   time.Time
	Level  Level
	Source string
	Msg    string
	Err    error
}

type ServiceState

type ServiceState struct {
	Name           string
	DesiredEnabled bool
	Active         bool
	Instances      int
	Failures       int
	LastError      string
	LastCheck      time.Time
}

Jump to

Keyboard shortcuts

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