forked from aksdb/CalAnonSync
Added function to create ICal
This commit is contained in:
parent
d7cc883cbb
commit
0209309bac
|
@ -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 }}
|
||||||
|
|
Loading…
Reference in New Issue