-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
59 lines (46 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"io/ioutil"
"log"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/golang-crew/Bolierplate-CRUD-Gingonic/docs"
"github.com/golang-crew/Bolierplate-CRUD-Gingonic/models"
"github.com/golang-crew/Bolierplate-CRUD-Gingonic/routers"
"github.com/spf13/viper"
_ "github.com/sirupsen/logrus"
_ "github.com/swaggo/gin-swagger"
_ "github.com/swaggo/gin-swagger/swaggerFiles"
)
// @APIVersion 1.0
// @Title Bolierplate CRUD API
// @Description This documentation describes bolierplate CRUD APIs
func main() {
r := gin.Default()
conf := &cors.Config{
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type", "x-user-auth-token"},
AllowCredentials: false,
MaxAge: 12 * time.Hour,
}
conf.AllowOrigins = []string{"*"}
r.Use(cors.New(*conf))
gin.SetMode(gin.DebugMode)
gin.DefaultWriter = ioutil.Discard
viper.SetConfigFile(`./config.json`)
err := viper.ReadInConfig()
if err != nil {
panic(err)
}
if viper.GetBool(`debug`) {
log.Println("Service RUN on DEBUG mode")
}
err = models.Init()
if err != nil {
panic(err)
}
routers.Init(r)
docs.SwaggerInfo.Host = "127.0.0.1:8080"
r.Run(":8080")
}