2024-10-23 15:36:30 +00:00
|
|
|
package helper
|
|
|
|
|
|
|
|
import (
|
2024-10-23 15:59:46 +00:00
|
|
|
"git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
2024-10-23 15:36:30 +00:00
|
|
|
"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
|
|
|
|
|
|
|
|
}
|