-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (40 loc) · 1.18 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
package main
import (
"os"
controller "personal-blog/controller"
middleware "personal-blog/middleware"
docs "personal-blog/docs"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
func main() {
docs.SwaggerInfo.Title = "Swagger Example API"
docs.SwaggerInfo.Description = "This is a sample server Petstore server."
docs.SwaggerInfo.Version = "1.0"
docs.SwaggerInfo.Host = "petstore.swagger.io"
docs.SwaggerInfo.BasePath = "/v2"
docs.SwaggerInfo.Schemes = []string{"http", "https"}
router := gin.Default()
v1 := router.Group("/api/v1")
{
post := v1.Group("/posts")
{
post.POST("", middleware.TokenAuthMiddleware(), controller.CreatePost)
post.PUT("", middleware.TokenAuthMiddleware(), controller.UpdatePost)
post.GET("/id/:id", controller.GetPostById)
post.GET("", controller.GetPosts)
post.GET("/categoryid/:categoryid", controller.GetPostsByCategoryId)
}
login := v1.Group("/login")
{
login.POST("/login", controller.Login)
}
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
router.Run(":" + port)
}