gateway_info.go 858 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
package dao

import (
	"goku-ce-1.0/dao/cache"
	"github.com/farseer810/yawf"
	"github.com/garyburd/redigo/redis"
	"goku-ce-1.0/dao/database"
)

func loadGatewayHashKey(gatewayAlias string) string{
	db := database.GetConnection()
	var gatewayHashKey string
	sql := `SELECT hashKey FROM eo_gateway WHERE gatewayAlias = ?; `
	err := db.QueryRow(sql,gatewayAlias).Scan(&gatewayHashKey)
	if err != nil {
		panic(err)
	}
	return gatewayHashKey
}

func GetGatewayHashKey(context yawf.Context,gatewayAlias string) string {
	var redisKey string = "gatewayHashKey:" + gatewayAlias
	conn := cache.GetConnection(context)
	gatewayHashKey, err := redis.String(conn.Do("GET", redisKey))
	if err == redis.ErrNil {
		gatewayHashKey = loadGatewayHashKey(gatewayAlias)
		conn.Do("SET", redisKey, gatewayHashKey)
	} else if err != nil {
		panic(err)
	}
	return gatewayHashKey
}