-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (51 loc) · 1.29 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
package main
import (
docs "API/docs"
"API/internal"
"API/internal/controllers"
"API/internal/controllers/auth"
"API/internal/controllers/user"
"API/internal/middlewares"
"API/internal/models"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"net/http"
"os"
)
func init() {
log.SetLevel(log.DebugLevel)
}
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @description Type "Bearer" followed by a space and JWT token.
func main() {
r := gin.Default()
docs.SwaggerInfo.BasePath = "/api/v1"
if os.Getenv("GIN_MODE") == "release" {
r.SetTrustedProxies([]string{os.Getenv("PROXY_IP")})
//panic("Database not setup for prod")
}
db := internal.GetDB()
db.AutoMigrate(&models.User{})
v1 := r.Group("/api/v1")
{
v1.GET("/ping", controllers.Helloworld)
v1.GET("/docs", func(c *gin.Context) {
c.Redirect(http.StatusSeeOther, "/api/v1/docs/index.html")
})
v1.GET("/docs/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
users := v1.Group("/users")
{
users.POST("/:username", user.Register)
users.GET("/:username", middlewares.JwtAuthMiddleware(), user.Fetch)
}
authGroup := v1.Group("/auth")
{
authGroup.POST("/login", auth.Login)
}
}
r.Run()
}