userConfig

package module
v0.0.0-...-16e743e Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2017 License: MIT Imports: 11 Imported by: 0

README

user-config

A go library for easily managing config files/directories in your XDGConfig directory

Documentation

Overview

Package userConfig eases the use of config files in a user's home directory

Package userConfig eases the use of config files in a user's home directory

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddonConfig

type AddonConfig struct {
	Name   string                       `toml:"-"`
	Path   string                       `toml:"-"`
	Values map[string]map[string]string `toml:"-"`
}

AddonConfig is an additional ConfigFile

func NewAddonConfig

func NewAddonConfig(name, path string) (*AddonConfig, error)

NewAddonConfig generates a Additional Config struct

func (*AddonConfig) Get

func (af *AddonConfig) Get(category, k string) string

Get gets a key/value pair from af

func (*AddonConfig) GetFullPath

func (af *AddonConfig) GetFullPath() string

GetFullPath returns the full path & filename to the config file

func (*AddonConfig) GetName

func (af *AddonConfig) GetName() string

GetName returns the name of this config file

func (*AddonConfig) GetPath

func (af *AddonConfig) GetPath() string

GetPath returns the path of this config file

func (*AddonConfig) Load

func (af *AddonConfig) Load() error

Load loads config files into the config

func (*AddonConfig) Save

func (af *AddonConfig) Save() error

Save writes the config to file(s)

func (*AddonConfig) Set

func (af *AddonConfig) Set(category, k, v string) error

Set sets a key/value pair in af, if unable to save, revert to old value (and return the error)

type Config

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

Config is a stuct for managing the config

func NewConfig

func NewConfig(name string) (*Config, error)

NewConfig generates a Config struct

func (*Config) DeleteKey

func (c *Config) DeleteKey(k string) error

DeleteKey at the config level removes a key from the <c.name>.conf file

func (*Config) Get

func (c *Config) Get(k string) string

Get at the config level retrieves a value from the <c.name>.conf file

func (*Config) GetArray

func (c *Config) GetArray(k string) ([]string, error)

func (*Config) GetBytes

func (c *Config) GetBytes(k string) []byte

GetBytes at the config level retrieves a value from the <c.name>.conf file and returns it as a byte slice

func (*Config) GetConfigPath

func (c *Config) GetConfigPath() string

GetConfigPath just returns the config path

func (*Config) GetDateTime

func (c *Config) GetDateTime(k string) (time.Time, error)

GetDateTime at the config level retrieves a value from the <c.name>.conf file

func (*Config) GetInt

func (c *Config) GetInt(k string) (int, error)

GetInt at the config level retrieves a value from the <c.name>.conf file and returns it as an integer (or an error if conversion fails)

func (*Config) GetKeyList

func (c *Config) GetKeyList() []string

GetKeyList at the config level returns all keys in the <c.name>.conf file

func (*Config) Load

func (c *Config) Load() error

Load loads config files into the config

func (*Config) Save

func (c *Config) Save() error

Save writes the config to file(s)

func (*Config) Set

func (c *Config) Set(k, v string) error

Set at the config level sets a value in the <c.name>.conf file

func (*Config) SetArray

func (c *Config) SetArray(k string, v []string) error

SetArray saves a string slice in the <c.name>.conf file

func (*Config) SetBytes

func (c *Config) SetBytes(k string, v []byte) error

SetBytes at the config level sets a value in the <c.name>.conf file

func (*Config) SetDateTime

func (c *Config) SetDateTime(k string, v time.Time) error

SetDateTime saves a time.Time (as a string) in the <c.name>.conf file

func (*Config) SetInt

func (c *Config) SetInt(k string, v int) error

SetInt saves an integer (as a string) in the <c.name>.conf file

type GeneralConfig

type GeneralConfig struct {
	Name        string            `toml:"-"`
	Path        string            `toml:"-"`
	ConfigFiles []string          `toml:"additional_config"`
	RawFiles    []string          `toml:"raw_files"`
	Values      map[string]string `toml:"general"`
}

GeneralConfig is the basic config structure All configs make with package userConfig will have this file

func NewGeneralConfig

func NewGeneralConfig(name, path string) (*GeneralConfig, error)

NewGeneralConfig generates a General Config struct

func (*GeneralConfig) DeleteKey

func (gf *GeneralConfig) DeleteKey(k string) error

DeleteKey removes a key from the file

func (*GeneralConfig) Get

func (gf *GeneralConfig) Get(k string) string

Get gets a key/value pair from gf

func (*GeneralConfig) GetArray

func (gf *GeneralConfig) GetArray(k string) ([]string, error)

func (*GeneralConfig) GetBytes

func (gf *GeneralConfig) GetBytes(k string) []byte

GetBytes gets a key/value pair from gf and returns it as a byte slice Or an error if it fails for whatever reason

func (*GeneralConfig) GetDateTime

func (gf *GeneralConfig) GetDateTime(k string) (time.Time, error)

GetDateTime gets a key/value pair from gf and returns it as a time.Time An error if it can't be converted

func (*GeneralConfig) GetInt

func (gf *GeneralConfig) GetInt(k string) (int, error)

GetInt gets a key/value pair from gf and return it as an integer An error if it can't be converted

func (*GeneralConfig) GetKeyList

func (gf *GeneralConfig) GetKeyList() []string

GetKeyList returns a list of all keys in the config file

func (*GeneralConfig) Load

func (gf *GeneralConfig) Load() error

Load loads config files into the config

func (*GeneralConfig) Save

func (gf *GeneralConfig) Save() error

Save writes the config to file(s)

func (*GeneralConfig) Set

func (gf *GeneralConfig) Set(k, v string) error

Set sets a key/value pair in gf, if unable to save, revert to old value (and return the error)

func (*GeneralConfig) SetArray

func (gf *GeneralConfig) SetArray(k string, v []string) error

SetArray sets a string slice value (as a string) in the config file

func (*GeneralConfig) SetBytes

func (gf *GeneralConfig) SetBytes(k string, v []byte) error

SetBytes at the config level sets a value in the <c.name>.conf file

func (*GeneralConfig) SetDateTime

func (gf *GeneralConfig) SetDateTime(k string, v time.Time) error

SetDateTime sets a DateTime value (as a string) in the config file

func (*GeneralConfig) SetInt

func (gf *GeneralConfig) SetInt(k string, v int) error

SetInt sets an integer value (as a string) in the config file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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