summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorayyansea <ayyansea@gmail.com>2024-11-21 22:58:38 +0300
committerayyansea <ayyansea@gmail.com>2024-11-21 22:58:38 +0300
commit7f9ea2a5c01076017b01164a885be46215f33546 (patch)
treef2800336bc483e60e473d776e880a46f29a07fa0 /internal/config
parentb3c0f0d863ae80cde48a7c0462d9b784b6193c6e (diff)
feat: use config file and FilterList
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go36
1 files changed, 3 insertions, 33 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index ad35ee7..683c229 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -1,56 +1,26 @@
package config
import (
- "errors"
"fmt"
"os"
- "path/filepath"
"gopkg.in/yaml.v3"
)
type Config struct {
- Filters []string `yaml:"filters"`
- Iterations int `yaml:"iterations"`
+ Filters []string `yaml:"filters"`
}
-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)
- }
- }
-
+func (c *Config) LoadConfig(filepath string) {
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
}