state

package
v0.13.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultStatePath

func DefaultStatePath() string

DefaultStatePath returns the default state file path.

Types

type PersistentProxyConfig

type PersistentProxyConfig struct {
	ID         string `json:"id"`
	TargetURL  string `json:"target_url"`
	Port       int    `json:"port"`
	MaxLogSize int    `json:"max_log_size"`
	Path       string `json:"path"`
	CreatedAt  string `json:"created_at"`
}

PersistentProxyConfig stores the configuration needed to recreate a proxy.

type PersistentState

type PersistentState struct {
	Version         int                     `json:"version"`
	OverlayEndpoint string                  `json:"overlay_endpoint,omitempty"`
	Proxies         []PersistentProxyConfig `json:"proxies,omitempty"`
	UpdatedAt       string                  `json:"updated_at"`
}

PersistentState stores daemon state that should survive restarts.

type StateManager

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

StateManager handles persisting and restoring daemon state.

func NewStateManager

func NewStateManager(config StateManagerConfig) *StateManager

NewStateManager creates a new state manager.

func (*StateManager) AddProxy

func (sm *StateManager) AddProxy(config PersistentProxyConfig)

AddProxy adds a proxy configuration to state.

func (*StateManager) Clear

func (sm *StateManager) Clear() error

Clear removes all state.

func (*StateManager) Flush

func (sm *StateManager) Flush() error

Flush ensures any pending saves are written immediately.

func (*StateManager) GetOverlayEndpoint

func (sm *StateManager) GetOverlayEndpoint() string

GetOverlayEndpoint returns the persisted overlay endpoint.

func (*StateManager) GetProxies

func (sm *StateManager) GetProxies() []PersistentProxyConfig

GetProxies returns all persisted proxy configurations.

func (*StateManager) GetProxy

func (sm *StateManager) GetProxy(id string) (PersistentProxyConfig, bool)

GetProxy returns a specific proxy configuration.

func (*StateManager) Load

func (sm *StateManager) Load() error

Load loads state from disk.

func (*StateManager) RemoveProxy

func (sm *StateManager) RemoveProxy(id string)

RemoveProxy removes a proxy configuration from state.

func (*StateManager) Save

func (sm *StateManager) Save() error

Save saves state to disk.

func (*StateManager) SaveDebounced

func (sm *StateManager) SaveDebounced()

SaveDebounced saves state with debouncing to avoid excessive writes.

func (*StateManager) SetOverlayEndpoint

func (sm *StateManager) SetOverlayEndpoint(endpoint string)

SetOverlayEndpoint updates the overlay endpoint in state.

func (*StateManager) State

func (sm *StateManager) State() PersistentState

State returns a copy of the current state.

type StateManagerConfig

type StateManagerConfig struct {
	// StatePath is the path to the state file.
	// If empty, uses default location.
	StatePath string

	// SaveInterval is the minimum time between saves (debouncing).
	SaveInterval time.Duration

	// AutoLoad loads state on creation if true.
	AutoLoad bool
}

StateManagerConfig configures the state manager.

func DefaultStateManagerConfig

func DefaultStateManagerConfig() StateManagerConfig

DefaultStateManagerConfig returns sensible defaults.

Jump to

Keyboard shortcuts

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