Committing for merge

This commit is contained in:
Brian Buller 2016-03-31 06:41:31 -05:00
parent 437d19f0b4
commit 94deb74091
2 changed files with 5 additions and 35 deletions

View File

@ -49,7 +49,7 @@ func (c *Config) Load() error {
var cfgPath string
cfgPath = xdg.Config.Dirs()[0]
if cfgPath != "" {
cfgPath = cfgPath + "/" + c.name
cfgPath = cfgPath + string(os.PathSeparator) + c.name
if err = c.verifyOrCreateDirectory(cfgPath); err != nil {
return err
}
@ -70,37 +70,6 @@ func (c *Config) Save() error {
return errors.New("Bad setup.")
}
return c.generalConfig.Save()
/*
var cfgPath string
var configLines []string
//configLines = append(configLines, "server="+client.ServerAddr)
//configLines = append(configLines, "key="+client.ServerKey)
cfgPath = os.Getenv("HOME")
if cfgPath != "" {
cfgPath = cfgPath + "/.config"
if err := c.verifyOrCreateDirectory(cfgPath); err != nil {
return err
}
cfgPath = cfgPath + "/" + c.name
}
if cfgPath != "" {
file, err := os.Create(cfgPath)
if err != nil {
// Couldn't load config even though one was specified
return err
}
defer file.Close()
w := bufio.NewWriter(file)
for _, line := range configLines {
fmt.Fprintln(w, line)
}
if err = w.Flush(); err != nil {
return err
}
}
return nil
*/
}
// verifyOrCreateDirectory is a helper function for building an

View File

@ -5,6 +5,7 @@ import (
"bytes"
"errors"
"io/ioutil"
"os"
"strings"
"github.com/BurntSushi/toml"
@ -36,11 +37,11 @@ func NewGeneralConfig(name, path string) (*GeneralConfig, error) {
// Load loads config files into the config
func (gf *GeneralConfig) Load() error {
if strings.TrimSpace(gf.Name) == "" || strings.TrimSpace(gf.Path) == "" {
return errors.New("Invalid ConfigFile Name: " + gf.Path + "/" + gf.Name)
return errors.New("Invalid ConfigFile Name: " + gf.Path + string(os.PathSeparator) + gf.Name)
}
// Config files end with .conf
cfgPath := gf.Path + "/" + gf.Name + ".conf"
cfgPath := gf.Path + string(os.PathSeparator) + gf.Name + ".conf"
tomlData, err := ioutil.ReadFile(cfgPath)
if err != nil {
return err
@ -54,7 +55,7 @@ func (gf *GeneralConfig) Load() error {
// Save writes the config to file(s)
func (gf *GeneralConfig) Save() error {
buf := new(bytes.Buffer)
cfgPath := gf.Path + "/" + gf.Name + ".conf"
cfgPath := gf.Path + string(os.PathSeparator) + gf.Name + ".conf"
if err := toml.NewEncoder(buf).Encode(gf); err != nil {
return err
}