diff --git a/config.go b/config.go index ce0a796..859ad27 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/config_file.go b/config_file.go index 60bad54..b871673 100644 --- a/config_file.go +++ b/config_file.go @@ -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 }