Files
junhong_cmp_fiber/internal/handler/user.go

34 lines
717 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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")
}