Added function to create ICal

This commit is contained in:
Andreas Schneider 2018-04-01 20:12:36 +02:00
parent d7cc883cbb
commit 0209309bac
1 changed files with 31 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"encoding/xml" "encoding/xml"
"errors" "errors"
"fmt" "fmt"
@ -135,6 +136,35 @@ func ParseICal(r io.Reader) (*ICal, error) {
}, err }, err
} }
func CreateICal(uid, summary string, start, end time.Time) *ICal {
model := struct {
UID string
Summary string
Start string
End string
Now string
}{
UID: uid,
Summary: summary,
Start: start.UTC().Format(ICAL_TIME),
End: end.UTC().Format(ICAL_TIME),
Now: time.Now().UTC().Format(ICAL_TIME),
}
b := &bytes.Buffer{}
err := icalTemplate.Execute(b, model)
if err != nil {
// Internal stuff, so this really should not fail.
panic(err)
}
ical, err := ParseICal(b)
if err != nil {
// Internal stuff, so this really should not fail.
panic(err)
}
return ical
}
func NewCalDAV(settings ServerSettings) *CalDAV { func NewCalDAV(settings ServerSettings) *CalDAV {
return &CalDAV{ return &CalDAV{
httpClient: http.DefaultClient, httpClient: http.DefaultClient,
@ -238,7 +268,7 @@ type PropFindResponse struct {
} }
var icalTemplate = template.Must(template.New("icalTemplate").Parse(`BEGIN:VCALENDAR var icalTemplate = template.Must(template.New("icalTemplate").Parse(`BEGIN:VCALENDAR
PRODID:-//aksdb/calanonsync//EN PRODID:-//aksdb//calanonsync//EN
VERSION:2.0 VERSION:2.0
BEGIN:VEVENT BEGIN:VEVENT
UID:{{ .UID }} UID:{{ .UID }}