config

package
v0.0.0-...-b667a3b Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigInit

func ConfigInit(path string, recipes string, shopping string) bool

Creates a new config file, using the default template, using `path`.

If `recipes` or `shopping` are not empty, the passed string will be passed on to the new config file as locations for each. Otherwise, XDG_DATA_HOME defaults will be used.

If the recipe and shopping dirs don't already exist, they will be created.

`users.toml` will be added to config but not created until needed

func DefaultConfigPath

func DefaultConfigPath() string

Returns the default config filepath

func EnsureDataDirInit

func EnsureDataDirInit() error

Tests for the existence of the data directories, if they do not exist then they are created.

Returns nil on success

func EnsureUsersInit

func EnsureUsersInit() error

Tests for the existence of the users file, if it does not exist then an empty one will be created.

Returns nil on success

func GetHMACKeyBytes

func GetHMACKeyBytes() []byte

Returns the HMAC secret key as a byte slice

Panics if config has not been loaded

func IsLoaded

func IsLoaded() bool

func LoadConfig

func LoadConfig(path string) bool

Loads a `go-cook` config file and returns the parsed `Config` struct.

Leave path blank to use default location. NOTE: Defaults only work with Unix based OS atm

func LoadConfigEnv

func LoadConfigEnv()

Loads config from environment vars instead of a config file WARNING: Unimplemented

Types

type Config

type Config struct {
	Units    string         `toml:"units"`
	Recipe   RecipeConfig   `toml:"recipe"`
	Shopping ShoppingConfig `toml:"shopping"`
	Users    string         `toml:"users"`
	HMACKey  string         `toml:"hmac-key"`
}

Internal representations for configs, used to (de)serialize to toml

func GetConfig

func GetConfig() Config

Returns a copy of the config, this should be fetched before each use, as it may change during runtime (dat global mutability baby)

Panics if used before a load

type RecipeConfig

type RecipeConfig struct {
	Dir string `toml:"dir"`
}

Internal representations for configs, used to (de)serialize to toml

type ShoppingConfig

type ShoppingConfig struct {
	Dir string `toml:"dir"`
}

Internal representations for configs, used to (de)serialize to toml

Jump to

Keyboard shortcuts

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