generated from pkg/go-template
33 lines
761 B
Go
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)
|
||
|
}
|