config

package
v0.99.4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config holds configuration structures and loading logic.

Index

Constants

View Source
const (
	// DefaultConfigName is the default name of the config file
	DefaultConfigName = ".cdnscli"

	// DefaultConfigType is the default config file type
	DefaultConfigType = "yaml"

	// DefaultClientTimeout is the default client timeout
	DefaultClientTimeout = 10 * time.Second

	// DefaultOutputFormat is the default output format
	DefaultOutputFormat = "text"
)

Variables

This section is empty.

Functions

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the path to the config file that would be used.

func Save

func Save(cfg *Config) error

Save saves the configuration to the default config file.

Types

type CloudflareCredentials

type CloudflareCredentials struct {
	// APIToken is the Cloudflare API token
	APIToken string `mapstructure:"api_token" yaml:"api_token"`

	// APIKey is the Cloudflare API key (alternative to token)
	APIKey string `mapstructure:"api_key" yaml:"api_key"`

	// Email is the Cloudflare account email (required with APIKey)
	Email string `mapstructure:"email" yaml:"email"`
}

CloudflareCredentials holds Cloudflare-specific credentials.

type Config

type Config struct {
	// DefaultProvider is the name of the default provider to use
	DefaultProvider string `mapstructure:"default_provider" yaml:"default-provider,omitempty"`

	// Providers contains configuration for all DNS providers
	Providers map[string]ProviderConfig `mapstructure:"providers" yaml:"providers"`

	// ClientTimeout is the default timeout for API requests
	ClientTimeout time.Duration `mapstructure:"client_timeout" yaml:"client-timeout,omitempty"`

	// OutputFormat is the default output format
	OutputFormat string `mapstructure:"output_format" yaml:"output-format,omitempty"`

	// Debug enables debug output
	Debug bool `mapstructure:"debug" yaml:"debug"`
}

Config represents the main configuration structure.

func Load

func Load(cfgFile string) (*Config, error)

Load loads configuration from file, environment variables, and command line flags. Priority order: flags > env > config file > defaults

func (*Config) GetClientTimeout

func (c *Config) GetClientTimeout() time.Duration

GetClientTimeout returns the client timeout, ensuring it's at least 1 second.

func (*Config) GetProvider

func (c *Config) GetProvider(name string) (*ProviderConfig, error)

GetProvider returns the provider configuration by name. Returns an error if the provider is not found.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

type ProviderConfig

type ProviderConfig struct {
	// Type is the provider type (e.g., "cloudflare", "route53", "digitalocean")
	Type string `mapstructure:"type" yaml:"type"`

	// DisplayName is the custom display name for the provider (e.g., "Cloudflare", "Рога и Копыта")
	// If not set, a default display name will be used based on the provider type.
	DisplayName string `mapstructure:"display_name" yaml:"display-name,omitempty"`

	// Credentials holds provider-specific credentials
	Credentials map[string]interface{} `mapstructure:"credentials" yaml:"credentials"`

	// Options holds provider-specific options
	Options map[string]interface{} `mapstructure:"options" yaml:"options"`
}

ProviderConfig holds configuration for a specific DNS provider.

func (*ProviderConfig) GetCloudflareCredentials

func (pc *ProviderConfig) GetCloudflareCredentials() (*CloudflareCredentials, error)

GetCloudflareCredentials extracts Cloudflare credentials from provider config.

func (*ProviderConfig) GetRegRuCredentials added in v0.99.4

func (pc *ProviderConfig) GetRegRuCredentials() (*RegRuCredentials, error)

GetRegRuCredentials extracts RegRu credentials from provider config.

func (*ProviderConfig) Validate

func (pc *ProviderConfig) Validate(name string) error

Validate validates a provider configuration.

type RegRuCredentials added in v0.99.4

type RegRuCredentials struct {
	// Username is the RegRu account username
	Username string `mapstructure:"username" yaml:"username"`

	// Password is the RegRu account password
	Password string `mapstructure:"password" yaml:"password"`
}

RegRuCredentials holds RegRu-specific credentials.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a configuration validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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