refactor: set config directory path in constants package
This commit is contained in:
parent
942f9cc0a8
commit
d316eb2133
2 changed files with 17 additions and 6 deletions
|
|
@ -42,13 +42,8 @@ func DefaultConfig() Config {
|
|||
|
||||
// Reads the configuration file and parses it.
|
||||
func Load() (*Config, error) {
|
||||
path, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := DefaultConfig()
|
||||
path = filepath.Join(path, constants.Name, "config.toml")
|
||||
path := filepath.Join(constants.ConfigDirPath, "config.toml")
|
||||
f, err := os.Open(path)
|
||||
if os.IsNotExist(err) {
|
||||
return &cfg, nil
|
||||
|
|
|
|||
|
|
@ -1,7 +1,23 @@
|
|||
package constants
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const Name = "discordo"
|
||||
|
||||
const UserAgent = Name + "/0.1 (https://github.com/diamondburned/arikawa, v3)"
|
||||
|
||||
const TmpFilePattern = Name + "_*.md"
|
||||
|
||||
var ConfigDirPath string
|
||||
|
||||
func init() {
|
||||
path, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
path = "."
|
||||
}
|
||||
|
||||
ConfigDirPath = filepath.Join(path, Name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue