You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
628 B
32 lines
628 B
package common
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// @Title md5签名
|
|
// @Param src string true "签名元数据"
|
|
func Md5(src string) string {
|
|
toolMd5 := md5.New()
|
|
toolMd5.Write([]byte(src))
|
|
return hex.EncodeToString(toolMd5.Sum(nil))
|
|
}
|
|
|
|
// @Title 获取登录用户userId
|
|
func GetUserId(c *gin.Context) uint {
|
|
uid, flag := c.Get("userId")
|
|
if !flag {
|
|
return 0
|
|
}
|
|
return uid.(uint)
|
|
}
|
|
|
|
// @Title 昵称加星号
|
|
func HideNickname(nickname string) string {
|
|
nameRune := []rune(nickname)
|
|
return fmt.Sprintf("%v****%s", string(nameRune[0:1]), string(nameRune[len(nameRune)-1]))
|
|
}
|