-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.go
41 lines (32 loc) · 807 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"log"
"github.com/pionus/arry"
"github.com/pionus/arry/middlewares"
)
func main() {
a := arry.New()
a.Use(middlewares.Gzip)
a.Use(middlewares.Logger())
a.Use(middlewares.Panic)
api := NewAPI()
router := a.Router()
router.Get("/work", func(ctx arry.Context) {
work := api.GetWorkCalendar()
ctx.SetContentType("text/calendar;charset=UTF-8")
ctx.Response().Code = 200
work.Render(ctx.Response().Writer)
})
router.Get("/off", func(ctx arry.Context) {
off := api.GetOffCalendar()
ctx.SetContentType("text/calendar;charset=UTF-8")
ctx.Response().Code = 200
off.Render(ctx.Response().Writer)
})
log.Printf("Listening at :80")
err := a.Start(":80")
if err != nil {
log.Fatalf("Could not start server: %s\n", err.Error())
}
log.Printf("shutdown")
}