aconfig

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 7 Imported by: 0

README

aconfig

Simple flexible application configuration in golang

This work in progress is the result of the author getting tired of writing separate configuration modules for every application. It is designed to work on Linux, macOS, and Windows.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithFind

func WithFind(filenames []string) func(*AConfig) error

func WithFindOrCreate

func WithFindOrCreate(filenames []string) func(*AConfig) error

func WithKeyConstraints

func WithKeyConstraints(keys []string) func(*AConfig) error

func WithLoad

func WithLoad(fileName string) func(*AConfig) error

func WithLoadOrCreate

func WithLoadOrCreate(filename string) func(*AConfig) error

func WithWindowsRegistry

func WithWindowsRegistry(key string) func(*AConfig) error

Types

type AConfig

type AConfig struct {
	Loaded             bool              // Configuration loaded
	WindowsRegistry    bool              // Use the Windows registry (ignored on non-Windows systems)
	WindowsRegistryKey string            // Windows registry key (ignored on non-Windows systems)
	ConfigFile         string            // Path to configuration file
	KeyList            []string          // List of keys
	Data               map[string]string // Configuration data
}

AConfig holds all configuration data

func New

func New(options ...func(*AConfig) error) (*AConfig, error)

New returns an AConfig instance

func (*AConfig) Checkpoint

func (c *AConfig) Checkpoint() error

Checkpoint saves the configuration to the last loaded file

func (*AConfig) Dump

func (c *AConfig) Dump()

Dump configuration to stdout for diagnostics

func (*AConfig) Exists

func (c *AConfig) Exists(key string) bool

Exists checks if the specified configuration key exits

func (*AConfig) GetBool

func (c *AConfig) GetBool(key string) (bool, error)

GetBool retrieves a boolean value or returns an error

func (*AConfig) GetBoolDefault

func (c *AConfig) GetBoolDefault(key string, defaultValue bool) bool

GetBoolDefault retrieves a boolean value or the specified default

func (*AConfig) GetInt

func (c *AConfig) GetInt(key string) (int, error)

GetInt retrieves an integer value or returns an error

func (*AConfig) GetInt64

func (c *AConfig) GetInt64(key string) (int64, error)

GetInt64 retrieves an int64 value or returns an error

func (*AConfig) GetInt64Default

func (c *AConfig) GetInt64Default(key string, defaultValue int64) int64

GetInt64Default retrieves an int64 value or returns the specified default

func (*AConfig) GetIntDefault

func (c *AConfig) GetIntDefault(key string, defaultValue int) int

GetIntDefault retrieves an integer value or returns the specified default

func (*AConfig) GetStr

func (c *AConfig) GetStr(key string) (string, error)

GetStr retrieves a string value or returns an error

func (*AConfig) GetStrDefault

func (c *AConfig) GetStrDefault(key string, defaultValue string) string

GetStrDefault retrieves a string value or returns the specified default

func (*AConfig) Init

func (c *AConfig) Init()

Init initializes the configuration data

func (*AConfig) Save

func (c *AConfig) Save(filename string) error

Save the configuration to the specified file

func (*AConfig) SetBool

func (c *AConfig) SetBool(key string, value bool) error

SetBool sets a boolean value

func (*AConfig) SetInt

func (c *AConfig) SetInt(key string, value int) error

SetInt sets an integer value

func (*AConfig) SetInt64

func (c *AConfig) SetInt64(key string, value int64) error

SetInt64 sets an int64 value

func (*AConfig) SetStr

func (c *AConfig) SetStr(key string, value string) error

SetStr sets a string value

Jump to

Keyboard shortcuts

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