Skip to content

Commit

Permalink
feat(icalendar): add icalendar support
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wing committed Mar 15, 2023
1 parent b31e6a7 commit d388eba
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func NewApi(s *store.Store, srv *service.Service) http.Handler {
sr.GET("/profiles/:key", handler.ProfileGet)
sr.PUT("/profiles/:key", handler.ProfileSet)

sr.GET("/calender.ics", handler.Calendar)

r.NoRoute(func(c *gin.Context) {
fmt.Println(c.Request.URL)
c.JSON(http.StatusNotFound, gin.H{
Expand Down
48 changes: 48 additions & 0 deletions app/api/v3/calendar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package v3

import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/emersion/go-ical"
)

func (h *Handler) Calendar(c *gin.Context) {
cal := ical.NewCalendar()

propProductID := ical.NewProp(ical.PropProductID)
propProductID.Value = "gosd"
cal.Props.Add(propProductID)

propVersion := ical.NewProp(ical.PropVersion)
propVersion.Value = "2.0"
cal.Props.Add(propVersion)
com := ical.NewComponent("VEVENT")

propSummary := ical.NewProp(ical.PropSummary)
propSummary.Value = "TTT"
com.Props.Add(propSummary)

DTStart := ical.NewProp(ical.PropDateTimeStart)
DTStart.Value = "20230311T032125Z"
com.Props.Add(DTStart)

DTStamp := ical.NewProp(ical.PropDateTimeStamp)
DTStamp.Value = "20230311T032125Z"
com.Props.Add(DTStamp)

Uid := ical.NewProp(ical.PropUID)
Uid.Value = "47E591E3-945A-4057-9A9F-EC4F0809D9D3"
com.Props.Add(Uid)

cal.Children = append(cal.Children, com)

//ev := ical.NewEvent()
//ev.DateTimeStart(time.Now())
cal.Children = append(cal.Children, )
//c.Writer.Header().Set("Content-Disposition", `attachment; filename*=UTF-8''`+"url.QueryEscape(blob.Name)")
if err := ical.NewEncoder(c.Writer).Encode(cal); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
Expand Down Expand Up @@ -64,6 +65,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/teambition/rrule-go v1.7.2 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/eclipse/paho.golang v0.10.0 h1:oUGPjRwWcZQRgDD9wVDV7y7i7yBSxts3vcvcNJo8B4Q=
github.com/eclipse/paho.golang v0.10.0/go.mod h1:rhrV37IEwauUyx8FHrvmXOKo+QRKng5ncoN1vJiJMcs=
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f h1:feGUUxxvOtWVOhTko8Cbmp33a+tU0IMZxMEmnkoAISQ=
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f/go.mod h1:2MKFUgfNMULRxqZkadG1Vh44we3y5gJAtTBlVsx1BKQ=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -257,6 +259,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/teambition/rrule-go v1.7.2 h1:goEajFWYydfCgavn2m/3w5U+1b3PGqPUHx/fFSVfTy0=
github.com/teambition/rrule-go v1.7.2/go.mod h1:mBJ1Ht5uboJ6jexKdNUJg2NcwP8uUMNvStWXlJD3MvU=
github.com/tidwall/gjson v1.12.1 h1:ikuZsLdhr8Ws0IdROXUS1Gi4v9Z4pGqpX/CvJkxvfpo=
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand Down

0 comments on commit d388eba

Please sign in to comment.