Beispiel #1
0
func Initialize(kvStorage gof.Storage) {
	if kvStorage.DriverName() == storage.DriveRedisStorage {
		_kvCacheStorage = kvStorage
	} else {
		panic(errors.New("only support redis storage now."))
	}
}
Beispiel #2
0
// 移除会员令牌
func RemoveMemberApiToken(sto gof.Storage, memberId int, token string) bool {
	srcToken, _ := GetMemberApiToken(sto, memberId)
	if len(srcToken) == 0 && srcToken == token {
		var key string = GetMemberApiTokenKey(memberId)
		sto.Del(key)
		sto.Del(key + "base")

	}
	return false
}
Beispiel #3
0
// 获取会员的API令牌
func GetMemberApiToken(sto gof.Storage, memberId int) (string, string) {
	chkStorage(sto)

	var key = GetMemberApiTokenKey(memberId)
	var srcToken, tokenBase string

	srcToken, _ = sto.GetString(key)
	tokenBase, _ = sto.GetString(key + "base")
	return srcToken, tokenBase
}
Beispiel #4
0
// 设置令牌,并返回
func SetMemberApiToken(sto gof.Storage, memberId int, pwd string) string {
	chkStorage(sto)
	cyp := crypto.NewUnixCrypto(pwd+offset, offset)
	var token string = string(cyp.Encode())
	var key string = GetMemberApiTokenKey(memberId)

	sto.Set(key, token)      // 存储令牌
	sto.Set(key+"base", pwd) // 存储令牌凭据

	return token
}
Beispiel #5
0
// 获取商户信息缓存
func GetValueMerchantCache(merchantId int) *merchant.Merchant {
	var v merchant.Merchant
	var sto gof.Storage = GetKVS()
	var key string = GetValueMerchantCacheCK(merchantId)
	if sto.Get(key, &v) != nil {
		v2, err := dps.MerchantService.GetMerchant(merchantId)
		if v2 != nil && err == nil {
			sto.SetExpire(key, *v2, DefaultMaxSeconds)
			return v2
		}
	}
	return &v

}
Beispiel #6
0
// 获取商户站点配置
func GetPartnerSiteConf(partnerId int) *partner.SiteConf {
	var v *partner.SiteConf
	var sto gof.Storage = GetKVS()
	var key string = GetPartnerSiteConfCK(partnerId)

	if sto.Driver() == storage.DriveHashStorage {
		if obj, err := GetKVS().GetRaw(key); err != nil {
			v = obj.(*partner.SiteConf)
		}
	} else if sto.Driver() == storage.DriveRedisStorage {
		sto.Get(key, &v)
	}

	if v == nil {
		if v = dps.PartnerService.GetSiteConf(partnerId); v != nil {
			sto.Set(key, v)
		}
	}
	return v
}
Beispiel #7
0
// 获取商户信息缓存
func GetValuePartnerCache(partnerId int) *partner.ValuePartner {
	var v *partner.ValuePartner
	var sto gof.Storage = GetKVS()
	var key string = GetValuePartnerCacheCK(partnerId)

	if sto.Driver() == storage.DriveHashStorage {
		if obj, err := GetKVS().GetRaw(key); err != nil {
			v = obj.(*partner.ValuePartner)
		}
	} else if sto.Driver() == storage.DriveRedisStorage {
		sto.Get(key, &v)
	}

	if v == nil {
		var err error
		if v, err = dps.PartnerService.GetPartner(partnerId); err == nil {
			sto.Set(key, v)
		}

	}
	return v
}