-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
71 lines (56 loc) · 1.6 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
package main
import (
"fmt"
"github.com/pilinux/postmark/controller"
"github.com/pilinux/postmark/migration"
"github.com/pilinux/gorest/config"
"github.com/pilinux/gorest/database"
"github.com/pilinux/gorest/lib/middleware"
"github.com/gin-gonic/gin"
)
var configure = config.Config()
func main() {
if err := database.InitDB().Error; err != nil {
fmt.Println(err)
}
// Migrate database
// DBMigrate(true): drop previous tables
// DBMigrate(false): create tables with missing columns and missing indexes
migration.DBMigrate(false)
router := SetupRouter()
router.Run(":" + configure.Server.ServerPort)
}
// SetupRouter ...
func SetupRouter() *gin.Engine {
// debug or release mode
if configure.Server.ServerEnv == "production" {
gin.SetMode(gin.ReleaseMode)
}
// gin.Default() = gin.New() + gin.Logger() + gin.Recovery()
router := gin.Default()
// Which proxy to trust
if configure.Security.TrustedIP == "nil" {
router.SetTrustedProxies(nil)
} else {
if configure.Security.TrustedIP != "" {
router.SetTrustedProxies([]string{configure.Security.TrustedIP})
}
}
router.Use(middleware.CORS())
router.Use(middleware.SentryCapture(configure.Logger.SentryDsn))
router.Use(middleware.Firewall(
configure.Security.Firewall.ListType,
configure.Security.Firewall.IP,
))
// API:v1
v1 := router.Group("webhooks/v1")
{
// basic auth
user := configure.Security.BasicAuth.Username
pass := configure.Security.BasicAuth.Password
v1.Use(gin.BasicAuth(gin.Accounts{user: pass}))
// postmark webhooks for outbound
v1.POST("outbound-events", controller.Outbound)
}
return router
}