-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (49 loc) · 1.23 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
package main
import (
"fmt"
"redis/utils"
"redis/views"
log "github.com/Sirupsen/logrus"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
cors "github.com/tommy351/gin-cors"
)
// GetEngine
func GetEngine() *gin.Engine {
router := gin.Default()
router.Use(gin.ErrorLoggerT(gin.ErrorTypePrivate))
router.Use(cors.Middleware(cors.Options{}))
router.Use(location.Default())
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
router.GET("/v1/emails", views.GetEmails)
router.POST("/v1/emails", views.AddEmail)
router.GET("/v1/email/:email", views.GetEmail)
router.PUT("/v1/email/:email", views.UpdateEmail)
router.DELETE("/v1/email/:email", views.DeleteEmail)
return router
}
func initApp() {
viper.AddConfigPath(".")
viper.SetConfigName("config")
viper.SetConfigType("toml")
err := viper.ReadInConfig()
if err != nil {
log.Error(err)
}
err = utils.InitRedisClient()
if err != nil {
log.Error(err)
}
log.SetFormatter(&log.TextFormatter{ForceColors: true})
log.SetLevel(log.DebugLevel)
}
func main() {
initApp()
gin.SetMode(gin.DebugMode)
defer utils.CloseRedisClient()
router := GetEngine()
router.Run(fmt.Sprintf(":%s", viper.GetString("server.port")))
}