Skip to content

Commit

Permalink
refactor: set config directory path in constants package
Browse files Browse the repository at this point in the history
  • Loading branch information
ayn2op committed Aug 31, 2024
1 parent 942f9cc commit d316eb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 1 addition & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit d316eb2

Please sign in to comment.