1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "icloudapp.cn/tools/entity"
- "icloudapp.cn/tools/errors"
- "icloudapp.cn/tools/util"
- )
- func HandleNext(ctx *gin.Context, err error) bool {
- if err != nil {
- entity.ResponseHandleBody(ctx, errors.GetCode(err), errors.GetMsg(err), entity.EmptyBodyObject())
- return false
- }
- return true
- }
- // GetUID 获取用户ID,来源jwt中间
- func GetUID(ctx *gin.Context) int64 {
- uidParam, exist := ctx.Get("jwt_uid")
- var uid int64 = 0
- if !exist {
- return 0
- }
- if err := util.ConvertAssign(&uid, uidParam); err != nil {
- return 0
- }
- return uid
- }
- // GetUsername 获取用户名,来源jwt中间
- func GetUsername(ctx *gin.Context) string {
- usernameParam, exist := ctx.Get("jwt_username")
- if !exist {
- return ""
- }
- var username string
- if err := util.ConvertAssign(&username, usernameParam); err != nil {
- return ""
- }
- return username
- }
|