From 3d967b586c8b277a5fd2ddc16289856205144036 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Thu, 14 Nov 2024 00:27:43 +0100 Subject: Fix loading config --- config.go | 16 +++++++++++++++- icalproxy.go | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index d9a2e30..746e437 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,7 @@ package main import ( + "encoding" "encoding/base64" "encoding/json" "log" @@ -14,8 +15,21 @@ type userToken struct { Salt []byte `json:"salt"` } +type jsonURL url.URL + +func (u *jsonURL) UnmarshalText(v []byte) error { + parsed, err := url.Parse(string(v)) + if err != nil { + return err + } + *u = jsonURL(*parsed) + return nil +} + +var _ encoding.TextUnmarshaler = new(jsonURL) + type config struct { - CalendarURL url.URL `json:"calendar_url"` + CalendarURL jsonURL `json:"calendar_url"` Ignore ignoreRules `json:"ignore"` Port string `json:"port"` UserTokens map[string]userToken `json:"user_tokens"` diff --git a/icalproxy.go b/icalproxy.go index cf09e5d..9ca1b33 100644 --- a/icalproxy.go +++ b/icalproxy.go @@ -15,7 +15,11 @@ func main() { cfg := loadConfig() printConfig(&cfg) - handler := handler{ignore: cfg.Ignore, tokens: cfg.UserTokens} + handler := handler{ + calURL: url.URL(cfg.CalendarURL), + ignore: cfg.Ignore, + tokens: cfg.UserTokens, + } mux := http.ServeMux{} mux.HandleFunc("/", handler.handle) -- cgit v1.2.3