state

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package state provides the per-Server runtime state container.

AppState is a pure value type: every Server constructs one via NewAppState and threads it through the components that need to read the proxy mode or the per-distro mirror URLs. There is no package-level singleton; multiple Server instances in the same process can hold independent AppState values and never collide on writes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppState added in v0.9.0

type AppState struct {
	Ubuntu      *MirrorState
	UbuntuPorts *MirrorState
	Debian      *MirrorState
	CentOS      *MirrorState
	Alpine      *MirrorState
	// contains filtered or unexported fields
}

AppState manages the complete runtime state for a single Server: the proxy mode and the mirror configuration for every supported distro.

func NewAppState added in v0.9.0

func NewAppState() *AppState

NewAppState constructs a fresh AppState with empty MirrorStates for every supported distro.

func (*AppState) Clone added in v0.9.0

func (s *AppState) Clone() *AppState

Clone returns a deep copy of the AppState. The clone shares no mutable state with the original.

func (*AppState) GetMirror added in v0.9.0

func (s *AppState) GetMirror(distType int) *url.URL

GetMirror returns the mirror URL for a specific distro type, or nil when unset / unknown.

func (*AppState) GetProxyMode added in v0.9.0

func (s *AppState) GetProxyMode() int

GetProxyMode returns the active proxy mode.

func (*AppState) ResetAll added in v0.9.0

func (s *AppState) ResetAll()

ResetAll clears every per-distro mirror state.

func (*AppState) SetMirror added in v0.9.0

func (s *AppState) SetMirror(distType int, input string)

SetMirror sets the mirror URL for a specific distro type. Unknown types are ignored.

func (*AppState) SetMirrorWithRegistry added in v0.12.0

func (s *AppState) SetMirrorWithRegistry(distType int, input string, reg *distro.Registry)

SetMirrorWithRegistry behaves like SetMirror but resolves aliases via the supplied registry.

func (*AppState) SetProxyMode added in v0.9.0

func (s *AppState) SetProxyMode(mode int)

SetProxyMode sets the active proxy mode (one of distro.Type*).

type MirrorState added in v0.9.0

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

MirrorState manages the mirror URL for a specific distribution.

The URL is stored as an atomic.Pointer[url.URL]. Reads (the hot path for every proxied request) are lock-free; writes (Set/Reset) replace the pointer atomically. We never mutate a *url.URL after publishing it, so callers can hold the returned pointer without racing future writers.

func NewMirrorState added in v0.9.0

func NewMirrorState(distType int) *MirrorState

NewMirrorState creates a new MirrorState for the given distro type.

func (*MirrorState) Clone added in v0.9.0

func (m *MirrorState) Clone() *MirrorState

Clone returns an independent MirrorState that contains a deep copy of the stored URL.

func (*MirrorState) Get added in v0.9.0

func (m *MirrorState) Get() *url.URL

Get returns the current mirror URL, or nil if unset.

Callers receive the same *url.URL the writer published; never mutate it.

func (*MirrorState) Reset added in v0.9.0

func (m *MirrorState) Reset()

Reset clears the mirror URL.

func (*MirrorState) Set added in v0.9.0

func (m *MirrorState) Set(input string)

Set updates the mirror URL.

An empty input or an unparseable URL clears the state (and logs a warning for the latter so misconfigurations are surfaced).

func (*MirrorState) SetWithRegistry added in v0.12.0

func (m *MirrorState) SetWithRegistry(input string, reg *distro.Registry)

SetWithRegistry updates the mirror URL, resolving aliases against the supplied registry when one is provided. The nil-registry branch keeps the simple Set call usable in tests / callers that do not need alias resolution.

Jump to

Keyboard shortcuts

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