-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 990 Bytes
/
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
package main
import (
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "serverChallenge/docs"
"serverChallenge/handlers"
"serverChallenge/routes"
)
// @title Server Challenge API
// @version 1.0
// @description This is a basic API using Gin and Gorm.
// @host https://lshuang.dev
// @BasePath /api
func main() {
var myEnv map[string]string
myEnv, _ = godotenv.Read()
var ginMode string
if myEnv["ENV"] != "production" {
ginMode = gin.DebugMode
} else {
ginMode = gin.ReleaseMode
}
gin.SetMode(ginMode)
router := gin.Default()
opts := []func(config *ginSwagger.Config){
ginSwagger.DefaultModelsExpandDepth(-1)}
router.GET("/docs/*any", ginSwagger.WrapHandler(swaggerfiles.Handler, opts...))
router.Use(handlers.ErrorHandler)
router.LoadHTMLGlob("views/*")
routes.Main(router)
if myEnv["PORT"] == "" {
myEnv["PORT"] = "8080"
}
router.Run(":" + myEnv["PORT"])
}