Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import (
"github.com/leonlatsch/go-resolve/internal/serialization"
)

const CONFIG_DIR = "config"
const CONFIG_FILE = CONFIG_DIR + "/" + "config.json"
const CONFIG_FILE_MODE = 0644
const (
CONFIG_DIR = "config"
CONFIG_FILE = CONFIG_DIR + "/" + "config.json"
CONFIG_FILE_MODE = 0o644
)

// Get the config as pointer. Value updates when file changes
func GetConfig() (*models.Config, error) {
if !configExists() {
createEmptyConfig()
return nil, errors.New("No Config. Creating empty config and exiting.")
return nil, errors.New("no Config. Creating empty config and exiting")
}

config, err := loadConfig()
Expand All @@ -41,7 +43,7 @@ func SaveConfig(conf models.Config) error {
return err
}

os.Mkdir(CONFIG_DIR, CONFIG_FILE_MODE) // Ignore err. Just try every time
os.Mkdir(CONFIG_DIR, 0o755) // Ignore err. Just try every time
if err := os.WriteFile(CONFIG_FILE, []byte(confJson), CONFIG_FILE_MODE); err != nil {
return err
}
Expand All @@ -53,7 +55,6 @@ func SaveConfig(conf models.Config) error {
func loadConfig() (models.Config, error) {
var config models.Config
buf, err := os.ReadFile(CONFIG_FILE)

if err != nil {
return config, err
}
Expand Down