Externalized settings

This commit is contained in:
Andreas Schneider 2018-03-31 18:52:32 +02:00
parent 678578dcac
commit 20a1ebbf1f
2 changed files with 36 additions and 1 deletions

View File

@ -151,7 +151,9 @@ func (e *EWSCalendar) getCalendarItems(folder *FolderId, start, end time.Time) (
} }
func main() { func main() {
e := NewEWSCalendar("https://outlook.live.com/EWS/Exchange.asmx", "", "") s := LoadSettings()
e := NewEWSCalendar(s.EWS.URL, s.EWS.Username, s.EWS.Password)
id, err := e.getCalendarFolderID() id, err := e.getCalendarFolderID()
if err != nil { if err != nil {
log.Println(err) log.Println(err)

View File

@ -0,0 +1,33 @@
package main
import (
"encoding/json"
"os"
)
type ServerSettings struct {
URL string
Username string
Password string
}
type Settings struct {
EWS ServerSettings
CalDAV ServerSettings
Anonymize struct {
Title string
}
}
func LoadSettings() Settings {
f, err := os.Open("calanonsync.json")
if err != nil {
panic(err)
}
settings := Settings{}
err = json.NewDecoder(f).Decode(&settings)
if err != nil {
panic(err)
}
return settings
}