aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2024-11-14 00:27:43 +0100
committerLibravatar Rutger Broekhoff2024-11-14 00:27:43 +0100
commit3d967b586c8b277a5fd2ddc16289856205144036 (patch)
tree24318cd79b977bb03c1b9b7a7247d77fb87388d3
parent14265a959cc3a527ab923731e121d08159872571 (diff)
downloadicalproxy-3d967b586c8b277a5fd2ddc16289856205144036.tar.gz
icalproxy-3d967b586c8b277a5fd2ddc16289856205144036.zip
Fix loading config
-rw-r--r--config.go16
-rw-r--r--icalproxy.go6
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 @@
1package main 1package main
2 2
3import ( 3import (
4 "encoding"
4 "encoding/base64" 5 "encoding/base64"
5 "encoding/json" 6 "encoding/json"
6 "log" 7 "log"
@@ -14,8 +15,21 @@ type userToken struct {
14 Salt []byte `json:"salt"` 15 Salt []byte `json:"salt"`
15} 16}
16 17
18type jsonURL url.URL
19
20func (u *jsonURL) UnmarshalText(v []byte) error {
21 parsed, err := url.Parse(string(v))
22 if err != nil {
23 return err
24 }
25 *u = jsonURL(*parsed)
26 return nil
27}
28
29var _ encoding.TextUnmarshaler = new(jsonURL)
30
17type config struct { 31type config struct {
18 CalendarURL url.URL `json:"calendar_url"` 32 CalendarURL jsonURL `json:"calendar_url"`
19 Ignore ignoreRules `json:"ignore"` 33 Ignore ignoreRules `json:"ignore"`
20 Port string `json:"port"` 34 Port string `json:"port"`
21 UserTokens map[string]userToken `json:"user_tokens"` 35 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() {
15 cfg := loadConfig() 15 cfg := loadConfig()
16 printConfig(&cfg) 16 printConfig(&cfg)
17 17
18 handler := handler{ignore: cfg.Ignore, tokens: cfg.UserTokens} 18 handler := handler{
19 calURL: url.URL(cfg.CalendarURL),
20 ignore: cfg.Ignore,
21 tokens: cfg.UserTokens,
22 }
19 23
20 mux := http.ServeMux{} 24 mux := http.ServeMux{}
21 mux.HandleFunc("/", handler.handle) 25 mux.HandleFunc("/", handler.handle)