feat(*): go 后端项目脚手架
This commit is contained in:
35
internal/api/handler/user.go
Normal file
35
internal/api/handler/user.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/zhilv666/navsite/internal/service"
|
||||
"github.com/zhilv666/navsite/pkg/common"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// getUserByID
|
||||
// @Summary 获取指定 ID 用户
|
||||
// @Tag User
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "用户 ID"
|
||||
// @Success 200 {object} common.Response[model.User] "获取成功"
|
||||
// @Failure 400 {object} common.Response[any] "获取失败"
|
||||
// @Router /api/v1/user/{id} [get]
|
||||
func getUserByID(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
idInt, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
common.Fail(c, err.Error())
|
||||
}
|
||||
user, err := service.GetUserByID(uint(idInt))
|
||||
if err != nil {
|
||||
common.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
common.Succ(c, user)
|
||||
}
|
||||
|
||||
func RegisterRouterUser(g *gin.RouterGroup) {
|
||||
g.GET(":id", getUserByID)
|
||||
}
|
||||
Reference in New Issue
Block a user