diff options
| author | ayyansea <ayyansea@gmail.com> | 2024-11-15 23:15:00 +0300 |
|---|---|---|
| committer | ayyansea <ayyansea@gmail.com> | 2024-11-15 23:15:00 +0300 |
| commit | c0d7adb1a1b28b6b1de9ccd95d4963a8342ccdbc (patch) | |
| tree | 1de133ef28e1f846e58bdaa49beb17dd1857424c /internal/config | |
| parent | cc7f4da0796fbd76301173dede6791f4525bf8e0 (diff) | |
feat: add Filters
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/internal/config/config.go b/internal/config/config.go deleted file mode 100644 index ad35ee7..0000000 --- a/internal/config/config.go +++ /dev/null @@ -1,56 +0,0 @@ -package config - -import ( - "errors" - "fmt" - "os" - "path/filepath" - - "gopkg.in/yaml.v3" -) - -type Config struct { - Filters []string `yaml:"filters"` - Iterations int `yaml:"iterations"` -} - -func getDefaultConfigPath() (defaultPath string, err error) { - programName := "uptfs" - configFileName := "config.yaml" - - if xdg := os.Getenv("XDG_CONFIG_HOME"); xdg != "" { - return filepath.Join(xdg, programName, configFileName), nil - } - - if home := os.Getenv("HOME"); home != "" { - return filepath.Join(home, programName, configFileName), nil - } - - return "", errors.New("both XDG_CONFIG_HOME and HOME are not set, can't proceed") -} - -func (c *Config) LoadConfig(filepath string) *Config { - if filepath == "" { - var err error - filepath, err = getDefaultConfigPath() - - if err != nil { - fmt.Printf("%v\n", err) - os.Exit(1) - } - } - - yamlFile, err := os.ReadFile(filepath) - - if err != nil { - fmt.Printf("%v\n", err) - os.Exit(1) - } - err = yaml.Unmarshal(yamlFile, c) - if err != nil { - fmt.Printf("%v\n", err) - os.Exit(1) - } - - return c -} |
