Fixed ical-go package include

This commit is contained in:
kolaente 2019-05-24 19:45:33 +02:00
parent a7bbaf7c5f
commit 24f06b2da5
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
15 changed files with 126 additions and 56 deletions

2
go.mod
View file

@ -44,7 +44,7 @@ require (
github.com/jgautheron/goconst v0.0.0-20170703170152-9740945f5dcb github.com/jgautheron/goconst v0.0.0-20170703170152-9740945f5dcb
github.com/labstack/echo/v4 v4.1.5 github.com/labstack/echo/v4 v4.1.5
github.com/labstack/gommon v0.2.8 github.com/labstack/gommon v0.2.8
github.com/laurent22/ical-go v0.1.0 github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 // indirect github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 // indirect
github.com/mattn/go-oci8 v0.0.0-20181130072307-052f5d97b9b6 // indirect github.com/mattn/go-oci8 v0.0.0-20181130072307-052f5d97b9b6 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect github.com/mattn/go-runewidth v0.0.4 // indirect

5
go.sum
View file

@ -27,7 +27,6 @@ github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMe
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cweill/gotests v1.5.3 h1:k3t4wW/x/YNixWZJhUIn+mivmK5iV1tJVOwVYkx0UcU=
github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U= github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U=
github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo= github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -122,8 +121,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0= github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0=
github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4= github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
github.com/laurent22/ical-go v0.1.0 h1:4vZHBD3/+ne+IN+c3B+v6d9Ff8+70pzTjCWsjfDRvL0= github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef h1:RZnRnSID1skF35j/15KJ6hKZkdIC/teQClJK5wP5LU4=
github.com/laurent22/ical-go v0.1.0/go.mod h1:4LATl0uhhtytR6p9n1AlktDyIz4u2iUnWEdI3L/hXiw= github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef/go.mod h1:4LATl0uhhtytR6p9n1AlktDyIz4u2iUnWEdI3L/hXiw=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=

View file

@ -20,7 +20,7 @@ import (
"code.vikunja.io/api/pkg/caldav" "code.vikunja.io/api/pkg/caldav"
"code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models" "code.vikunja.io/api/pkg/models"
"github.com/laurent22/ical-go/ical" "github.com/laurent22/ical-go"
"strconv" "strconv"
"time" "time"
) )

21
vendor/github.com/laurent22/ical-go/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Laurent Cozic
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

25
vendor/github.com/laurent22/ical-go/README.md generated vendored Normal file
View file

@ -0,0 +1,25 @@
# ical-go
iCal package for Go (Golang)
## Installation
go get github.com/laurent22/ical-go
## Status
Currently, the package doesn't support the full iCal specification. It's still a work in progress towards that goal.
The most useful function in the package is:
```go
func ParseCalendar(data string) (*Node, error)
```
Parses a VCALENDAR string, unwrap and unfold lines, etc. and put all this into a usable structure (a collection of `Node`s with name, value, type, etc.).
With the `Node` in hand, you can use several of its functions to, e.g., find specific parameters, children, etc.
## License
MIT

View file

@ -9,6 +9,7 @@ type CalendarEvent struct {
Summary string Summary string
Description string Description string
Location string Location string
URL string
CreatedAtUTC *time.Time CreatedAtUTC *time.Time
ModifiedAtUTC *time.Time ModifiedAtUTC *time.Time
StartAt *time.Time StartAt *time.Time

View file

@ -1,9 +0,0 @@
package ical
const (
VCALENDAR = "VCALENDAR"
VEVENT = "VEVENT"
DTSTART = "DTSTART"
DTEND = "DTEND"
DURATION = "DURATION"
)

View file

@ -1,8 +1,8 @@
package ical package ical
import ( import (
"fmt"
"bytes" "bytes"
"fmt"
) )
type strBuffer struct { type strBuffer struct {

View file

@ -1,9 +1,9 @@
package ical package ical
import ( import (
"time"
"regexp" "regexp"
"strconv" "strconv"
"time"
) )
type Node struct { type Node struct {
@ -44,19 +44,28 @@ func (this *Node) PropString(name string, defaultValue string) string {
func (this *Node) PropDate(name string, defaultValue time.Time) time.Time { func (this *Node) PropDate(name string, defaultValue time.Time) time.Time {
node := this.ChildByName(name) node := this.ChildByName(name)
if node == nil { return defaultValue } if node == nil {
return defaultValue
}
tzid := node.Parameter("TZID", "") tzid := node.Parameter("TZID", "")
allDay := node.Parameter("VALUE", "") == "DATE"
var output time.Time var output time.Time
var err error var err error
if tzid != "" { if tzid != "" {
loc, err := time.LoadLocation(tzid) loc, err := time.LoadLocation(tzid)
if err != nil { panic(err) } if err != nil {
panic(err)
}
output, err = time.ParseInLocation("20060102T150405", node.Value, loc) output, err = time.ParseInLocation("20060102T150405", node.Value, loc)
} else if allDay {
output, err = time.Parse("20060102", node.Value)
} else { } else {
output, err = time.Parse("20060102T150405Z", node.Value) output, err = time.Parse("20060102T150405Z", node.Value)
} }
if err != nil { panic(err) } if err != nil {
panic(err)
}
return output return output
} }
@ -91,9 +100,13 @@ func (this *Node) PropDuration(name string) time.Duration {
func (this *Node) PropInt(name string, defaultValue int) int { func (this *Node) PropInt(name string, defaultValue int) int {
n := this.PropString(name, "") n := this.PropString(name, "")
if n == "" { return defaultValue } if n == "" {
return defaultValue
}
output, err := strconv.Atoi(n) output, err := strconv.Atoi(n)
if err != nil { panic(err) } if err != nil {
panic(err)
}
return output return output
} }
@ -102,9 +115,13 @@ func (this *Node) DigProperty(propPath... string) (string, bool) {
} }
func (this *Node) Parameter(name string, defaultValue string) string { func (this *Node) Parameter(name string, defaultValue string) string {
if len(this.Parameters) <= 0 { return defaultValue } if len(this.Parameters) <= 0 {
return defaultValue
}
v, ok := this.Parameters[name] v, ok := this.Parameters[name]
if !ok { return defaultValue } if !ok {
return defaultValue
}
return v return v
} }

View file

@ -1,8 +1,8 @@
package ical package ical
import ( import (
"log"
"errors" "errors"
"log"
"regexp" "regexp"
"strings" "strings"
) )
@ -30,7 +30,9 @@ func parseCalendarNode(lines []string, lineIndex int) (*Node, bool, error, int)
parameters = make(map[string]string) parameters = make(map[string]string)
for i := 1; i < len(splitted); i++ { for i := 1; i < len(splitted); i++ {
p := strings.Split(splitted[i], "=") p := strings.Split(splitted[i], "=")
if len(p) != 2 { panic("Invalid parameter format: " + name) } if len(p) != 2 {
panic("Invalid parameter format: " + name)
}
parameters[p[0]] = p[1] parameters[p[0]] = p[1]
} }
} }

9
vendor/github.com/laurent22/ical-go/properties.go generated vendored Normal file
View file

@ -0,0 +1,9 @@
package ical
const (
VCALENDAR = "VCALENDAR"
VEVENT = "VEVENT"
DTSTART = "DTSTART"
DTEND = "DTEND"
DURATION = "DURATION"
)

View file

@ -1,8 +1,8 @@
package ical package ical
import ( import (
"time"
"strings" "strings"
"time"
) )
type calSerializer struct { type calSerializer struct {
@ -64,6 +64,7 @@ func (this *calEventSerializer) serializeEvent() {
this.summary() this.summary()
this.description() this.description()
this.location() this.location()
this.url()
this.end() this.end()
} }
@ -91,6 +92,10 @@ func (this *calEventSerializer) location() {
this.serializeStringProp("LOCATION", this.event.Location) this.serializeStringProp("LOCATION", this.event.Location)
} }
func (this *calEventSerializer) url() {
this.serializeStringProp("URL", this.event.URL)
}
func (this *calEventSerializer) dtstart() { func (this *calEventSerializer) dtstart() {
this.serializeTimeProp("DTSTART", this.event.StartAtUTC()) this.serializeTimeProp("DTSTART", this.event.StartAtUTC())
} }

4
vendor/modules.txt vendored
View file

@ -88,8 +88,8 @@ github.com/labstack/gommon/log
github.com/labstack/gommon/color github.com/labstack/gommon/color
github.com/labstack/gommon/bytes github.com/labstack/gommon/bytes
github.com/labstack/gommon/random github.com/labstack/gommon/random
# github.com/laurent22/ical-go v0.1.0 # github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef
github.com/laurent22/ical-go/ical github.com/laurent22/ical-go
# github.com/magiconair/properties v1.8.0 # github.com/magiconair/properties v1.8.0
github.com/magiconair/properties github.com/magiconair/properties
# github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 # github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983