-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
44 lines (37 loc) · 1020 Bytes
/
router.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
package main
import (
"fmt"
"github.com/clanbeat/mailer/Godeps/_workspace/src/github.com/gin-gonic/gin"
"github.com/clanbeat/mailer/src/sender"
"log"
"os"
)
func initRoutes(templatePath string) {
log.Println("init router")
tmplts := createRender(templatePath)
router := gin.New()
router.HTMLRender = tmplts
router.Use(gin.Logger())
router.Use(RecoveryMiddleware(os.Stdout, errorTracker))
router.GET("/emails/:name", getEmail)
router.OPTIONS("/emails/:name")
router.GET("/test/:name/:email", sendTest)
router.OPTIONS("/test/:name/:email")
router.GET("/status", getStatus)
router.OPTIONS("/status")
v1 := router.Group("/v1")
{
v1.POST("/send", postEmail)
v1.OPTIONS("/send")
}
//start server
log.Println(fmt.Sprintf("=> Starting in %s on http://0.0.0.0:%s", env.Env, os.Getenv("PORT")))
router.Run(":" + os.Getenv("PORT"))
}
func createRender(templatePath string) sender.TemplateCache {
c, err := sender.BuildTemplateCache(templatePath)
if err != nil {
fatalError(err)
}
return c
}