Name config files ".conf"
This commit is contained in:
parent
a59425cd2e
commit
f64aa66979
22
config.go
22
config.go
@ -25,54 +25,54 @@ func NewConfig(name string) (*Config, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetKeyList at the config level returns all keys in the <c.name>.toml file
|
// GetKeyList at the config level returns all keys in the <c.name>.conf file
|
||||||
func (c *Config) GetKeyList() []string {
|
func (c *Config) GetKeyList() []string {
|
||||||
return c.generalConfig.GetKeyList()
|
return c.generalConfig.GetKeyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set at the config level sets a value in the <c.name>.toml file
|
// Set at the config level sets a value in the <c.name>.conf file
|
||||||
func (c *Config) Set(k, v string) error {
|
func (c *Config) Set(k, v string) error {
|
||||||
return c.generalConfig.Set(k, v)
|
return c.generalConfig.Set(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBytes at the config level sets a value in the <c.name>.toml file
|
// SetBytes at the config level sets a value in the <c.name>.conf file
|
||||||
func (c *Config) SetBytes(k string, v []byte) error {
|
func (c *Config) SetBytes(k string, v []byte) error {
|
||||||
return c.generalConfig.SetBytes(k, v)
|
return c.generalConfig.SetBytes(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetInt saves an integer (as a string) in the <c.name>.toml file
|
// SetInt saves an integer (as a string) in the <c.name>.conf file
|
||||||
func (c *Config) SetInt(k string, v int) error {
|
func (c *Config) SetInt(k string, v int) error {
|
||||||
return c.generalConfig.SetInt(k, v)
|
return c.generalConfig.SetInt(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDateTime saves a time.Time (as a string) in the <c.name>.toml file
|
// SetDateTime saves a time.Time (as a string) in the <c.name>.conf file
|
||||||
func (c *Config) SetDateTime(k string, v time.Time) error {
|
func (c *Config) SetDateTime(k string, v time.Time) error {
|
||||||
return c.generalConfig.SetDateTime(k, v)
|
return c.generalConfig.SetDateTime(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetArray saves a string slice in the <c.name>.toml file
|
// SetArray saves a string slice in the <c.name>.conf file
|
||||||
func (c *Config) SetArray(k string, v []string) error {
|
func (c *Config) SetArray(k string, v []string) error {
|
||||||
return c.generalConfig.SetArray(k, v)
|
return c.generalConfig.SetArray(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get at the config level retrieves a value from the <c.name>.toml file
|
// Get at the config level retrieves a value from the <c.name>.conf file
|
||||||
func (c *Config) Get(k string) string {
|
func (c *Config) Get(k string) string {
|
||||||
return c.generalConfig.Get(k)
|
return c.generalConfig.Get(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBytes at the config level retrieves a value from the <c.name>.toml file
|
// GetBytes at the config level retrieves a value from the <c.name>.conf file
|
||||||
// and returns it as a byte slice
|
// and returns it as a byte slice
|
||||||
func (c *Config) GetBytes(k string) []byte {
|
func (c *Config) GetBytes(k string) []byte {
|
||||||
return c.generalConfig.GetBytes(k)
|
return c.generalConfig.GetBytes(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInt at the config level retrieves a value from the <c.name>.toml file
|
// 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)
|
// and returns it as an integer (or an error if conversion fails)
|
||||||
func (c *Config) GetInt(k string) (int, error) {
|
func (c *Config) GetInt(k string) (int, error) {
|
||||||
return c.generalConfig.GetInt(k)
|
return c.generalConfig.GetInt(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDateTime at the config level retrieves a value from the <c.name>.toml file
|
// GetDateTime at the config level retrieves a value from the <c.name>.conf file
|
||||||
func (c *Config) GetDateTime(k string) (time.Time, error) {
|
func (c *Config) GetDateTime(k string) (time.Time, error) {
|
||||||
return c.generalConfig.GetDateTime(k)
|
return c.generalConfig.GetDateTime(k)
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func (c *Config) GetArray(k string) ([]string, error) {
|
|||||||
return c.generalConfig.GetArray(k)
|
return c.generalConfig.GetArray(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteKey at the config level removes a key from the <c.name>.toml file
|
// DeleteKey at the config level removes a key from the <c.name>.conf file
|
||||||
func (c *Config) DeleteKey(k string) error {
|
func (c *Config) DeleteKey(k string) error {
|
||||||
return c.generalConfig.DeleteKey(k)
|
return c.generalConfig.DeleteKey(k)
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ func (gf *GeneralConfig) Load() error {
|
|||||||
return errors.New("Invalid ConfigFile Name: " + gf.Path + string(os.PathSeparator) + gf.Name)
|
return errors.New("Invalid ConfigFile Name: " + gf.Path + string(os.PathSeparator) + gf.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config files end with .toml
|
// Config files end with .conf
|
||||||
cfgPath := gf.Path + string(os.PathSeparator) + gf.Name + ".toml"
|
cfgPath := gf.Path + string(os.PathSeparator) + gf.Name + ".conf"
|
||||||
tomlData, err := ioutil.ReadFile(cfgPath)
|
tomlData, err := ioutil.ReadFile(cfgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Couldn't find the file, save a new one
|
// Couldn't find the file, save a new one
|
||||||
@ -61,7 +61,7 @@ func (gf *GeneralConfig) Load() error {
|
|||||||
// Save writes the config to file(s)
|
// Save writes the config to file(s)
|
||||||
func (gf *GeneralConfig) Save() error {
|
func (gf *GeneralConfig) Save() error {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
cfgPath := gf.Path + string(os.PathSeparator) + gf.Name + ".toml"
|
cfgPath := gf.Path + string(os.PathSeparator) + gf.Name + ".conf"
|
||||||
if err := toml.NewEncoder(buf).Encode(gf); err != nil {
|
if err := toml.NewEncoder(buf).Encode(gf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ func (gf *GeneralConfig) Set(k, v string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBytes at the config level sets a value in the <c.name>.toml file
|
// SetBytes at the config level sets a value in the <c.name>.conf file
|
||||||
func (gf *GeneralConfig) SetBytes(k string, v []byte) error {
|
func (gf *GeneralConfig) SetBytes(k string, v []byte) error {
|
||||||
return gf.Set(k, string(v))
|
return gf.Set(k, string(v))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user