-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (70 loc) · 1.86 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
r "gopkg.in/dancannon/gorethink.v2"
)
var (
rc *r.Session
tc *TwilioClient
apiKey string
)
func main() {
router := echo.New()
router.Use(middleware.Logger())
router.Use(middleware.Recover())
api := router.Group("/api")
api.Use(middleware.BasicAuth(AuthMiddleware))
api.GET("/users", UserListHandler)
api.PUT("/users", AddUserHandler)
api.DELETE("/users/:id", RemoveUserHandler)
api.GET("/webhooks", WebhookListHandler)
api.PUT("/webhooks", AddWebhookHandler)
api.DELETE("/webhooks/:id", RemoveWebhookHandler)
router.POST("/webhook/:name", WebhookHandler)
port := os.Getenv("PORT")
if port == "" {
port = ":1323"
}
icalURL := os.Getenv("PINGROLL_ICAL_URL")
if icalURL == "" {
log.Fatal("PINGROLL_ICAL_URL is required")
}
rehtinkUrl := os.Getenv("PINGROLL_RETHINK_URL")
if rehtinkUrl == "" {
log.Fatal("PINGROLL_RETHINK_URL is required")
}
twilioAccountSID := os.Getenv("PINGROLL_TWILIO_ACCOUNT_SID")
if twilioAccountSID == "" {
log.Fatal("PINGROLL_TWILIO_ACCOUNT_SID is required")
}
twilioAuthToken := os.Getenv("PINGROLL_TWILIO_AUTH_TOKEN")
if twilioAuthToken == "" {
log.Fatal("PINGROLL_TWILIO_AUTH_TOKEN is required")
}
twilioFromNumber := os.Getenv("PINGROLL_TWILIO_FROM_NUMBER")
if twilioFromNumber == "" {
log.Fatal("PINGROLL_TWILIO_FROM_NUMBER is required")
}
apiKey = os.Getenv("PINGROLL_API_KEY")
if apiKey == "" {
log.Fatal("PINGROLL_API_KEY is required")
}
var err error
rc, err = r.Connect(r.ConnectOpts{
Address: rehtinkUrl,
Database: "pingroll",
})
if err != nil {
log.Fatal(err)
}
tc = &TwilioClient{
AccountSID: twilioAccountSID,
AuthToken: twilioAuthToken,
FromNumber: twilioFromNumber,
}
ProcessIcal(icalURL)
router.Logger.Fatal(router.Start(port))
}