-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (42 loc) · 1.03 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
package main
import (
"go-api-scaffolding/controllers"
"go-api-scaffolding/middlewares"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
_ "go-api-scaffolding/docs"
"github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
)
// @title Some API
// @version 1.0
// @description API para gerênciar a busca de leilões.
// @BasePath /v1
func main() {
Environment()
router := gin.Default()
router.Use(middlewares.CORS)
v1 := router.Group("/api/models")
{
v1.Use(middlewares.Authentication)
modelController := new(controllers.ModelController)
v1.GET("/", modelController.Find)
v1.GET("/:modelID", modelController.Get)
}
router.NoRoute(func(c *gin.Context) {
c.AbortWithStatus(404)
})
swaggerHandler := ginSwagger.WrapHandler(swaggerFiles.Handler)
router.GET("/swagger/*any", swaggerHandler)
router.Run(":9000")
}
//Environment variables
func Environment() {
err := godotenv.Load()
if err != nil {
err := godotenv.Load("secrets/.env")
if err != nil {
panic(".env wasn't found.")
}
}
}