1 Star 0 Fork 0

MinKo-U/keyauth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bearer.go 691 Bytes
一键复制 编辑 原始数据 按行查看 历史
MinKo-U 提交于 2022-11-19 15:12 . first commit
package utils
import (
"math/rand"
"net/http"
"strings"
"time"
)
func MakeBearer(lenth int) string {
charlist := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
t := make([]string, lenth)
rand.Seed(time.Now().UnixNano() + int64(lenth) + rand.Int63n(10000))
for i := 0; i < lenth; i++ {
rn := rand.Intn(len(charlist))
w := charlist[rn : rn+1]
t = append(t, w)
}
token := strings.Join(t, "")
return token
}
func GetTokenRequestHttp(r *http.Request) string {
var tk string
auth := r.Header.Get("Authorization")
al := strings.Split(auth, " ")
if len(al) > 1 {
tk = al[1]
} else if len(al) == 1 {
if al[0] != "" {
tk = al[0]
}
}
return tk
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MinKo-U/keyauth.git
git@gitee.com:MinKo-U/keyauth.git
MinKo-U
keyauth
keyauth
v1.0.2

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385