做完了一部分,备份一下,防止以外删除
This commit is contained in:
33
internal/handler/user.go
Normal file
33
internal/handler/user.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
// GetUsers 获取用户列表(示例受保护端点)
|
||||
func GetUsers(c *fiber.Ctx) error {
|
||||
// 从上下文获取用户 ID(由 auth 中间件设置)
|
||||
userID := c.Locals(constants.ContextKeyUserID)
|
||||
|
||||
// 示例数据
|
||||
users := []fiber.Map{
|
||||
{
|
||||
"id": "user-123",
|
||||
"name": "张三",
|
||||
"email": "zhangsan@example.com",
|
||||
},
|
||||
{
|
||||
"id": "user-456",
|
||||
"name": "李四",
|
||||
"email": "lisi@example.com",
|
||||
},
|
||||
}
|
||||
|
||||
return response.SuccessWithMessage(c, fiber.Map{
|
||||
"users": users,
|
||||
"authenticated_as": userID,
|
||||
}, "success")
|
||||
}
|
||||
Reference in New Issue
Block a user