wqyblog_api_go/main.go

34 lines
607 B
Go
Raw Normal View History

2024-08-19 21:37:34 +08:00
package main
import (
"github.com/gin-gonic/gin"
"wqyblog_api_go/db"
"wqyblog_api_go/handlers"
)
2024-08-19 21:37:34 +08:00
func main() {
db.Init()
r := gin.Default()
r.GET("/", handlers.HalloWorld)
r.POST("/api/auth/login", handlers.Login)
r.GET("/api/posts", handlers.GetPosts)
r.GET("/api/posts/:id", handlers.GetPost)
authorized := r.Group("/")
authorized.Use(handlers.Authenticate)
{
authorized.POST("/api/posts", handlers.CreatePost)
authorized.PUT("/api/posts/:id", handlers.UpdatePost)
authorized.DELETE("/api/posts/:id", handlers.DeletePost)
}
err := r.Run(":8080")
if err != nil {
return
}
2024-08-19 21:37:34 +08:00
}