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 ¶
- type AppState
- func (s *AppState) Clone() *AppState
- func (s *AppState) GetMirror(distType int) *url.URL
- func (s *AppState) GetProxyMode() int
- func (s *AppState) ResetAll()
- func (s *AppState) SetMirror(distType int, input string)
- func (s *AppState) SetMirrorWithRegistry(distType int, input string, reg *distro.Registry)
- func (s *AppState) SetProxyMode(mode int)
- type MirrorState
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
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
GetMirror returns the mirror URL for a specific distro type, or nil when unset / unknown.
func (*AppState) GetProxyMode ¶ added in v0.9.0
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
SetMirror sets the mirror URL for a specific distro type. Unknown types are ignored.
func (*AppState) SetMirrorWithRegistry ¶ added in v0.12.0
SetMirrorWithRegistry behaves like SetMirror but resolves aliases via the supplied registry.
func (*AppState) SetProxyMode ¶ added in v0.9.0
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.