state

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package state holds the cached health status of a probe along with pub/sub semantics so transports (gRPC Watch, log/metric reporters, cached HTTP) can react to changes without re-running the underlying probe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

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

Registry maps service names to States. The empty name "" is conventionally used for the overall service status (matches grpc.health.v1 semantics).

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty Registry.

func (*Registry) Get

func (r *Registry) Get(name string) *State

Get returns the State for name, creating one if absent.

func (*Registry) Lookup

func (r *Registry) Lookup(name string) (*State, bool)

Lookup returns the State for name and whether it existed. Unlike Get, it does not create missing entries.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns a snapshot of registered service names.

type State

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

State is a thread-safe cached probe.Status with subscriber broadcast.

Subscribers receive the current status immediately on Subscribe, then any subsequent changes. The latest value wins — if a subscriber is slow, older updates are dropped while the channel is full.

Notifications are serialized with respect to Set: subscribers will never observe an ordering inconsistent with the status mutations themselves.

func New

func New() *State

New creates a State initialized to StatusUnknown. HasBeenSet returns false until the first Set call.

func (*State) Get

func (s *State) Get() probe.Status

Get returns the current cached status.

func (*State) HasBeenSet

func (s *State) HasBeenSet() bool

HasBeenSet reports whether Set has ever been called on this State. Used by transports (notably gRPC) to distinguish "service exists but its status was never reported" from "service status is genuinely up/down".

func (*State) Set

func (s *State) Set(st probe.Status) (prev probe.Status, changed bool)

Set replaces the cached status and notifies subscribers if the value changed. Returns the previous status and whether a change occurred.

The lock is held across subscriber notifications. drainSend is non-blocking, so this does not stall callers, and it guarantees that concurrent Set calls produce a notification order consistent with the final status.

func (*State) Subscribe

func (s *State) Subscribe(ctx context.Context) <-chan probe.Status

Subscribe returns a channel receiving status updates. The current value is delivered immediately. The channel is closed when ctx is canceled.

Jump to

Keyboard shortcuts

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