12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package Account
- import (
- "Yunlot/logs"
- "fmt"
- "github.com/astaxie/beego/cache"
- uuid "github.com/satori/go.uuid"
- "time"
- )
- var redis_Tokey cache.Cache
- func init() {
- var err error
- redis_Tokey, err = cache.NewCache("memory", `{"interval":60}`)
- if err != nil || redis_Tokey == nil {
- panic(any(err))
- }
- Redis_Tokey_Set("0533b4ec-049a-450f-93ec-d9984f219a66", "BOIYhGqm")
- }
- // ---------------- Redis -------------------
- // Redis_Set(m.T_sn,m) // Redis 更新缓存
- func Redis_Tokey_Set(key string, r string) (err error) {
- err = redis_Tokey.Put(key, r, 24*time.Hour)
- if err != nil {
- logs.Println("set key:", key, ",value:", r, err)
- }
- return
- }
- // if r,is :=Redis_Get(T_sn);is{
- // return r,nil
- // }
- func Redis_Tokey_Get(key string) (r string, is bool) {
- if redis_Tokey.IsExist(key) {
- //println("找到key:",key)
- v := redis_Tokey.Get(key)
- Redis_Tokey_Set(key, v.(string))
- return v.(string), true
- }
- //println("没有 找到key:",key)
- return "", false
- }
- func Redis_DelK(key string) (err error) {
- err = redis_Tokey.Delete(key)
- return
- }
- // ---------------- 方法 -------------------
- // 验证 TOKEY
- func Read_Tokey(User_tokey string) (string, bool) {
- return Redis_Tokey_Get(User_tokey)
- }
- // 添加 Tokey
- func Add_Tokey(User_uuid string) (Tokey string) {
- for true {
- Tokey = uuid.NewV4().String()
- _, is := Redis_Tokey_Get(Tokey)
- if !is {
- break
- }
- fmt.Print("申请 TOKEY 重复!重新生成。", Tokey)
- }
- Redis_Tokey_Set(Tokey, User_uuid)
- return Tokey
- }
|