ChronoTomato/internal/helper/config.go
Sebastian Mark 064056e8cb feat: update module path
- modify go.mod to reflect the new module path
- update config file path in the main function
- adjust import statements in various internal packages
- add install instructions to README

🤖
2024-10-23 21:21:23 +02:00

26 lines
546 B
Go

package helper
import (
"git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
"github.com/charmbracelet/log"
"gopkg.in/yaml.v2"
"os"
)
func ParseConfig(filename string) models.ConfigFile {
var config models.ConfigFile
yamlFile, err := os.ReadFile(filename)
if err != nil {
log.Error("Error opening config file!", "reason", err)
log.Info("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
}