Documentation
¶
Overview ¶
Package state provides application state management with support for both global singleton access (backward compatibility) and dependency injection patterns.
Index ¶
- Variables
- func GetAlpineMirror() *url.URL
- func GetCentOSMirror() *url.URL
- func GetDebianMirror() *url.URL
- func GetProxyMode() int
- func GetUbuntuMirror() *url.URL
- func GetUbuntuPortsMirror() *url.URL
- func ResetAlpineMirror()
- func ResetCentOSMirror()
- func ResetDebianMirror()
- func ResetUbuntuMirror()
- func ResetUbuntuPortsMirror()
- func SetAlpineMirror(input string)
- func SetCentOSMirror(input string)
- func SetDebianMirror(input string)
- func SetGlobal(state *AppState)
- func SetProxyMode(mode int)
- func SetUbuntuMirror(input string)
- func SetUbuntuPortsMirror(input string)
- type AppState
- type MirrorState
Constants ¶
This section is empty.
Variables ¶
var ( UbuntuMirror = &mirrorProxy{distType: distro.TypeUbuntu} UbuntuPortsMirror = &mirrorProxy{distType: distro.TypeUbuntuPorts} DebianMirror = &mirrorProxy{distType: distro.TypeDebian} CentOSMirror = &mirrorProxy{distType: distro.TypeCentOS} AlpineMirror = &mirrorProxy{distType: distro.TypeAlpine} )
These variables maintain backward compatibility with existing code that accesses mirrors directly. They delegate to the global AppState.
Functions ¶
func GetAlpineMirror ¶
func GetCentOSMirror ¶
func GetDebianMirror ¶
func GetProxyMode ¶
func GetProxyMode() int
func GetUbuntuMirror ¶
func GetUbuntuPortsMirror ¶ added in v0.9.0
func ResetAlpineMirror ¶
func ResetAlpineMirror()
func ResetCentOSMirror ¶
func ResetCentOSMirror()
func ResetDebianMirror ¶
func ResetDebianMirror()
func ResetUbuntuMirror ¶
func ResetUbuntuMirror()
func ResetUbuntuPortsMirror ¶ added in v0.9.0
func ResetUbuntuPortsMirror()
func SetAlpineMirror ¶
func SetAlpineMirror(input string)
func SetCentOSMirror ¶
func SetCentOSMirror(input string)
func SetDebianMirror ¶
func SetDebianMirror(input string)
func SetGlobal ¶ added in v0.9.0
func SetGlobal(state *AppState)
SetGlobal replaces the global AppState instance. This is useful for testing or when you want to use a custom state instance. Safe to call concurrently with Global().
func SetProxyMode ¶
func SetProxyMode(mode int)
func SetUbuntuMirror ¶
func SetUbuntuMirror(input string)
func SetUbuntuPortsMirror ¶ added in v0.9.0
func SetUbuntuPortsMirror(input string)
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 application state including proxy mode and mirror configurations for all supported distributions. This struct supports dependency injection for better testability.
func Global ¶ added in v0.9.0
func Global() *AppState
Global returns the global AppState instance. This is primarily for dependency injection scenarios where you need to pass the state explicitly.
func NewAppState ¶ added in v0.9.0
func NewAppState() *AppState
NewAppState creates a new AppState instance with initialized mirror states
func (*AppState) GetMirror ¶ added in v0.9.0
GetMirror returns the mirror URL for a specific distribution
func (*AppState) GetProxyMode ¶ added in v0.9.0
GetProxyMode returns the current proxy mode
func (*AppState) ResetAll ¶ added in v0.9.0
func (s *AppState) ResetAll()
ResetAll resets all mirror states
func (*AppState) SetMirror ¶ added in v0.9.0
SetMirror sets the mirror URL for a specific distribution
func (*AppState) SetProxyMode ¶ added in v0.9.0
SetProxyMode sets the proxy mode
type MirrorState ¶ added in v0.9.0
type MirrorState struct {
// contains filtered or unexported fields
}
MirrorState manages mirror URL states 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 instance
func (*MirrorState) Clone ¶ added in v0.9.0
func (m *MirrorState) Clone() *MirrorState
Clone creates a copy of the MirrorState containing a deep copy of the URL.
func (*MirrorState) Get ¶ added in v0.9.0
func (m *MirrorState) Get() *url.URL
Get returns the current mirror URL. 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 unparseable URL clears the state (and logs a warning for the latter so misconfigurations are surfaced).