icechen e932171ffa
All checks were successful
continuous-integration/drone/push Build is passing
feat: 封装中间件
2022-01-14 01:28:43 +08:00

33 lines
761 B
Go

package admin
import (
"git.icechen.cn/monorepo/backend/pkg/proto/zeus/lark"
"git.icechen.cn/monorepo/backend/pkg/rpc"
"github.com/gofiber/fiber/v2"
)
const AuthorizationHeader = "Authorization"
const UserInfoKey = "user_info"
type UserInfo = *lark.InfoResponse
// MiddlewareLarkAdmin 飞书管理员token校验
func MiddlewareLarkAdmin(c *fiber.Ctx) error {
token := c.Get(AuthorizationHeader)
response, err := lark.NewUserClient(rpc.GetServiceConn("lark")).Info(c.Context(), &lark.InfoRequest{
Token: token,
})
if err != nil {
return err
}
c.Context().SetUserValue(UserInfoKey, response)
return c.Next()
}
// GetUserInfo 获取用户信息
func GetUserInfo(c *fiber.Ctx) UserInfo {
return c.Context().UserValue(UserInfoKey).(UserInfo)
}