-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (30 loc) · 1.26 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
package main
import (
"mgo-skeleton/bin/configs"
rauth "mgo-skeleton/bin/modules/auth/routes"
rteam "mgo-skeleton/bin/modules/team/routes"
"mgo-skeleton/bin/pkg/database/postgres"
"net/http"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
configs.InitEnvironments()
db := postgres.ConnectPostgresql()
configCors := cors.DefaultConfig()
configCors.AllowAllOrigins = true
configCors.AllowHeaders = append(configCors.AllowHeaders, "Content-Type", "Content-Length", "Accept-Encoding", "X-XSRF-TOKEN", "X-CSRF-Token", "Authorization", "X-M2M-Origin", "Access-Control-Allow-Origin", "Access-Control-Allow-Methods", "Access-Control-Allow-Headers", "Access-Control-Allow-Credentials", "Origin", "Accept", "X-Requested-With", "access-control-allow-origin", "access-control-allow-methods", "access-control-allow-headers")
configCors.AllowMethods = append(configCors.AllowMethods, "Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, DELETE")
configCors.AllowCredentials = true
r := gin.Default()
r.Use(cors.New(configCors))
r.GET("/ping", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
routerGroup := r.Group("/api")
rauth.AuthRoute(routerGroup, db)
rteam.TeamRoute(routerGroup, db)
r.Run(":8080")
}