|
@@ -87,17 +87,19 @@ func New() *Config {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (cfg *Config) Load() error {
|
|
func (cfg *Config) Load() error {
|
|
|
- path, _ := os.UserConfigDir()
|
|
|
|
|
|
|
+ path := DirPath()
|
|
|
// Create the configuration directory if it does not exist already.
|
|
// Create the configuration directory if it does not exist already.
|
|
|
- path = filepath.Join(path, Name)
|
|
|
|
|
err := os.MkdirAll(path, os.ModePerm)
|
|
err := os.MkdirAll(path, os.ModePerm)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- path = filepath.Join(path, "config.yml")
|
|
|
|
|
// Open the configuration file with create and read-write flag.
|
|
// Open the configuration file with create and read-write flag.
|
|
|
- f, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, os.ModePerm)
|
|
|
|
|
|
|
+ f, err := os.OpenFile(
|
|
|
|
|
+ filepath.Join(path, "config.yml"),
|
|
|
|
|
+ os.O_CREATE|os.O_RDWR,
|
|
|
|
|
+ os.ModePerm,
|
|
|
|
|
+ )
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
@@ -115,3 +117,15 @@ func (cfg *Config) Load() error {
|
|
|
|
|
|
|
|
return yaml.NewDecoder(f).Decode(&cfg)
|
|
return yaml.NewDecoder(f).Decode(&cfg)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// DirPath returns the path of the configuration directory.
|
|
|
|
|
+func DirPath() string {
|
|
|
|
|
+ path, _ := os.UserConfigDir()
|
|
|
|
|
+ return filepath.Join(path, Name)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// LogDirPath returns the path of the log directory.
|
|
|
|
|
+func LogDirPath() string {
|
|
|
|
|
+ path, _ := os.UserCacheDir()
|
|
|
|
|
+ return filepath.Join(path, Name)
|
|
|
|
|
+}
|