config

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config provides configuration management for Moley.

Package config provides configuration management for Moley. It handles both global configuration (API tokens, etc.) and tunnel-specific configuration (tunnel settings, ingress rules, DNS configuration) with proper validation and defaults.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigManager

type ConfigManager[T any] struct {
	// contains filtered or unexported fields
}

ConfigManager is a generic configuration manager

func NewConfigManager

func NewConfigManager[T any](path string, defaultConfig *T) *ConfigManager[T]

NewConfigManager creates a new generic configuration manager

func (*ConfigManager[T]) BindEnv

func (cm *ConfigManager[T]) BindEnv(prefix string)

BindEnv binds environment variables to the config using viper

func (*ConfigManager[T]) BindFlags

func (cm *ConfigManager[T]) BindFlags(cmd *cobra.Command)

BindFlags binds CLI flags to the config using viper/cobra

func (*ConfigManager[T]) GetConfig

func (cm *ConfigManager[T]) GetConfig() *T

GetConfig returns the current configuration

func (*ConfigManager[T]) Load

func (cm *ConfigManager[T]) Load() error

Load loads the configuration from file or creates default if not exists

func (*ConfigManager[T]) Save

func (cm *ConfigManager[T]) Save() error

Save writes the configuration to file

func (*ConfigManager[T]) UpdateConfig

func (cm *ConfigManager[T]) UpdateConfig(updater func(*T)) error

UpdateConfig updates the configuration and saves it

func (*ConfigManager[T]) Validate

func (cm *ConfigManager[T]) Validate() error

Validate validates the configuration using struct tags

type GlobalConfig

type GlobalConfig struct {
	Cloudflare struct {
		Token string `mapstructure:"token" yaml:"token" validate:"required"`
	} `mapstructure:"cloudflare" yaml:"cloudflare"`
}

type GlobalConfigManager

type GlobalConfigManager struct {
	*ConfigManager[GlobalConfig]
}

GlobalConfigManager manages global configuration

func NewGlobalConfigManager

func NewGlobalConfigManager(cmd *cobra.Command) (*GlobalConfigManager, error)

NewGlobalConfigManager creates a new global configuration manager

func (*GlobalConfigManager) GetGlobalConfig

func (gcm *GlobalConfigManager) GetGlobalConfig() *GlobalConfig

GetGlobalConfig returns the global configuration

func (*GlobalConfigManager) UpdateGlobalConfig

func (gcm *GlobalConfigManager) UpdateGlobalConfig(updater func(*GlobalConfig)) error

UpdateGlobalConfig updates the global configuration and saves it

type TunnelConfig

type TunnelConfig struct {
	Tunnel  *domain.Tunnel  `mapstructure:"tunnel" yaml:"tunnel" validate:"required"`
	Ingress *domain.Ingress `mapstructure:"ingress" yaml:"ingress" validate:"required"`
}

type TunnelConfigManager

type TunnelConfigManager struct {
	*ConfigManager[TunnelConfig]
}

TunnelConfigManager manages tunnel configuration

func NewTunnelConfigManager

func NewTunnelConfigManager(configPath string) (*TunnelConfigManager, error)

NewTunnelConfigManager creates a new tunnel configuration manager

func (*TunnelConfigManager) GetTunnelConfig

func (tcm *TunnelConfigManager) GetTunnelConfig() *TunnelConfig

GetTunnelConfig returns the tunnel configuration

func (*TunnelConfigManager) UpdateTunnelConfig

func (tcm *TunnelConfigManager) UpdateTunnelConfig(updater func(*TunnelConfig)) error

UpdateTunnelConfig updates the tunnel configuration and saves it

Jump to

Keyboard shortcuts

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