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/labstack/echo/v4 v4.1.5
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/mattn/go-oci8 v0.0.0-20181130072307-052f5d97b9b6 // 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/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/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/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
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/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0=
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.0/go.mod h1:4LATl0uhhtytR6p9n1AlktDyIz4u2iUnWEdI3L/hXiw=
github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef h1:RZnRnSID1skF35j/15KJ6hKZkdIC/teQClJK5wP5LU4=
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/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
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/log"
"code.vikunja.io/api/pkg/models"
"github.com/laurent22/ical-go/ical"
"github.com/laurent22/ical-go"
"strconv"
"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

@ -7,7 +7,7 @@ type Calendar struct {
func (this *Calendar) Serialize() string {
serializer := calSerializer{
calendar: this,
buffer: new(strBuffer),
buffer: new(strBuffer),
}
return serializer.serialize()
}

View file

@ -5,14 +5,15 @@ import (
)
type CalendarEvent struct {
Id string
Summary string
Description string
Location string
CreatedAtUTC *time.Time
Id string
Summary string
Description string
Location string
URL string
CreatedAtUTC *time.Time
ModifiedAtUTC *time.Time
StartAt *time.Time
EndAt *time.Time
StartAt *time.Time
EndAt *time.Time
}
func (this *CalendarEvent) StartAtUTC() *time.Time {
@ -34,7 +35,7 @@ func (this *CalendarEvent) ToICS() string {
func (this *CalendarEvent) serializeWithBuffer(buffer *strBuffer) string {
serializer := calEventSerializer{
event: this,
event: this,
buffer: buffer,
}
return serializer.serialize()

View file

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

View file

@ -1,18 +1,18 @@
package ical
import (
"fmt"
"bytes"
"bytes"
"fmt"
)
type strBuffer struct {
buffer bytes.Buffer
buffer bytes.Buffer
}
func (b *strBuffer) Write(format string, elem ...interface{}) {
b.buffer.WriteString(fmt.Sprintf(format, elem...))
b.buffer.WriteString(fmt.Sprintf(format, elem...))
}
func (b *strBuffer) String() string {
return b.buffer.String()
return b.buffer.String()
}

View file

@ -1,17 +1,17 @@
package ical
import (
"time"
"regexp"
"strconv"
"time"
)
type Node struct {
Name string
Value string
Type int // 1 = Object, 0 = Name/Value
Name string
Value string
Type int // 1 = Object, 0 = Name/Value
Parameters map[string]string
Children []*Node
Children []*Node
}
func (this *Node) ChildrenByName(name string) []*Node {
@ -44,19 +44,28 @@ func (this *Node) PropString(name string, defaultValue string) string {
func (this *Node) PropDate(name string, defaultValue time.Time) time.Time {
node := this.ChildByName(name)
if node == nil { return defaultValue }
if node == nil {
return defaultValue
}
tzid := node.Parameter("TZID", "")
allDay := node.Parameter("VALUE", "") == "DATE"
var output time.Time
var err error
if tzid != "" {
loc, err := time.LoadLocation(tzid)
if err != nil { panic(err) }
if err != nil {
panic(err)
}
output, err = time.ParseInLocation("20060102T150405", node.Value, loc)
} else if allDay {
output, err = time.Parse("20060102", node.Value)
} else {
output, err = time.Parse("20060102T150405Z", node.Value)
}
if err != nil { panic(err) }
if err != nil {
panic(err)
}
return output
}
@ -86,29 +95,37 @@ func (this *Node) PropDuration(name string) time.Duration {
min := strToDuration(matches[2])
sec := strToDuration(matches[3])
return hours * time.Hour + min * time.Minute + sec * time.Second
return hours*time.Hour + min*time.Minute + sec*time.Second
}
func (this *Node) PropInt(name string, defaultValue int) int {
n := this.PropString(name, "")
if n == "" { return defaultValue }
if n == "" {
return defaultValue
}
output, err := strconv.Atoi(n)
if err != nil { panic(err) }
if err != nil {
panic(err)
}
return output
}
func (this *Node) DigProperty(propPath... string) (string, bool) {
func (this *Node) DigProperty(propPath ...string) (string, bool) {
return this.dig("prop", propPath...)
}
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]
if !ok { return defaultValue }
if !ok {
return defaultValue
}
return v
}
func (this *Node) DigParameter(paramPath... string) (string, bool) {
func (this *Node) DigParameter(paramPath ...string) (string, bool) {
return this.dig("param", paramPath...)
}
@ -120,7 +137,7 @@ func (this *Node) DigParameter(paramPath... string) (string, bool) {
// Example:
// dig("param", "VCALENDAR", "VEVENT", "DTEND", "TYPE") -> It will search for "VCALENDAR" node,
// then a "VEVENT" node, then a "DTEND" note, then finally the "TYPE" param.
func (this *Node) dig(valueType string, valuePath... string) (string, bool) {
func (this *Node) dig(valueType string, valuePath ...string) (string, bool) {
current := this
lastIndex := len(valuePath) - 1
for _, v := range valuePath[:lastIndex] {

View file

@ -1,8 +1,8 @@
package ical
import (
"log"
"errors"
"log"
"regexp"
"strings"
)
@ -10,7 +10,7 @@ import (
func ParseCalendar(data string) (*Node, error) {
r := regexp.MustCompile("([\r|\t| ]*\n[\r|\t| ]*)+")
lines := r.Split(strings.TrimSpace(data), -1)
node, _, err, _ := parseCalendarNode(lines, 0)
node, _, err, _ := parseCalendarNode(lines, 0)
return node, err
}
@ -30,11 +30,13 @@ func parseCalendarNode(lines []string, lineIndex int) (*Node, bool, error, int)
parameters = make(map[string]string)
for i := 1; i < len(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]
}
}
value := line[colonIndex+1:len(line)]
value := line[colonIndex+1 : len(line)]
if name == "BEGIN" {
node := new(Node)
@ -76,7 +78,7 @@ func parseCalendarNode(lines []string, lineIndex int) (*Node, bool, error, int)
func parseTextType(lines []string, lineIndex int) (string, int) {
line := lines[lineIndex]
colonIndex := strings.Index(line, ":")
output := strings.TrimSpace(line[colonIndex+1:len(line)])
output := strings.TrimSpace(line[colonIndex+1 : len(line)])
lineIndex++
for {
line := lines[lineIndex]

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,13 +1,13 @@
package ical
import (
"time"
"strings"
"strings"
"time"
)
type calSerializer struct {
calendar *Calendar
buffer *strBuffer
buffer *strBuffer
}
func (this *calSerializer) serialize() string {
@ -41,7 +41,7 @@ func (this *calSerializer) items() {
}
type calEventSerializer struct {
event *CalendarEvent
event *CalendarEvent
buffer *strBuffer
}
@ -62,8 +62,9 @@ func (this *calEventSerializer) serializeEvent() {
this.dtstart()
this.dtend()
this.summary()
this.description()
this.description()
this.location()
this.url()
this.end()
}
@ -91,6 +92,10 @@ func (this *calEventSerializer) location() {
this.serializeStringProp("LOCATION", this.event.Location)
}
func (this *calEventSerializer) url() {
this.serializeStringProp("URL", this.event.URL)
}
func (this *calEventSerializer) dtstart() {
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/bytes
github.com/labstack/gommon/random
# github.com/laurent22/ical-go v0.1.0
github.com/laurent22/ical-go/ical
# github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef
github.com/laurent22/ical-go
# github.com/magiconair/properties v1.8.0
github.com/magiconair/properties
# github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983