34 lines
717 B
Go
34 lines
717 B
Go
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")
|
||
}
|