package helper import ( "git.smsvc.net/pomodoro/ChronoTomato/pkg/models" "github.com/charmbracelet/log" "gopkg.in/yaml.v3" "os" "path/filepath" "strings" ) func ParseConfig(filename string) models.ConfigFile { var config models.ConfigFile if strings.HasPrefix(filename, "~/") { dirname, _ := os.UserHomeDir() filename = filepath.Join(dirname, filename[2:]) } yamlFile, err := os.ReadFile(filename) if err != nil { log.Warn("Error opening config file!", "reason", err) log.Warn("Using defaults") return models.ConfigFile{ URL: "ws://localhost:8080/ws", } } err = yaml.Unmarshal(yamlFile, &config) if err != nil { log.Fatalf("Unmarshal: %v", err) } return config }