state

package
v0.10.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 application state management with support for both global singleton access (backward compatibility) and dependency injection patterns.

Index

Constants

This section is empty.

Variables

View Source
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 GetAlpineMirror() *url.URL

func GetCentOSMirror

func GetCentOSMirror() *url.URL

func GetDebianMirror

func GetDebianMirror() *url.URL

func GetProxyMode

func GetProxyMode() int

func GetUbuntuMirror

func GetUbuntuMirror() *url.URL

func GetUbuntuPortsMirror added in v0.9.0

func GetUbuntuPortsMirror() *url.URL

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) Clone added in v0.9.0

func (s *AppState) Clone() *AppState

Clone creates a deep copy of the AppState

func (*AppState) GetMirror added in v0.9.0

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

GetMirror returns the mirror URL for a specific distribution

func (*AppState) GetProxyMode added in v0.9.0

func (s *AppState) GetProxyMode() int

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

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

SetMirror sets the mirror URL for a specific distribution

func (*AppState) SetProxyMode added in v0.9.0

func (s *AppState) SetProxyMode(mode int)

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).

Jump to

Keyboard shortcuts

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