34 lines
607 B
Go
34 lines
607 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"wqyblog_api_go/db"
|
|
"wqyblog_api_go/handlers"
|
|
)
|
|
|
|
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
|
|
}
|
|
}
|