Sebastian Mark
bbc9977f1c
- remove `shared` package and shared.Message - rename `notifications` package to `frontend` - introduce a channel send the received ServerMessages to the frontend handler(s) - move keyhandler to goroutine - simplify password handling in Start function - update import names when importing from GoTomoto
32 lines
718 B
Go
32 lines
718 B
Go
package helper
|
|
|
|
import (
|
|
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
|
"github.com/charmbracelet/log"
|
|
"gopkg.in/yaml.v3"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func ParseConfig(filename string) ChronoTomato.Config {
|
|
var config ChronoTomato.Config
|
|
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 ChronoTomato.Config{
|
|
URL: "ws://localhost:8080/ws",
|
|
}
|
|
}
|
|
err = yaml.Unmarshal(yamlFile, &config)
|
|
if err != nil {
|
|
log.Fatalf("Unmarshal: %v", err)
|
|
}
|
|
return config
|
|
|
|
}
|