Exemplo n.º 1
0
func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error) {
	key = utils.DESTINATION_PREFIX + key
	var values []byte
	if values, err = rs.db.Cmd("GET", key).Bytes(); len(values) > 0 && err == nil {
		b := bytes.NewBuffer(values)
		r, err := zlib.NewReader(b)
		if err != nil {
			return nil, err
		}
		out, err := ioutil.ReadAll(r)
		if err != nil {
			return nil, err
		}
		r.Close()
		dest = new(Destination)
		err = rs.ms.Unmarshal(out, dest)
		// create optimized structure
		for _, p := range dest.Prefixes {
			cache2go.Push(utils.DESTINATION_PREFIX+p, dest.Id)
		}
	} else {
		return nil, errors.New("not found")
	}
	return
}
Exemplo n.º 2
0
func (ms *MongoStorage) GetDestination(key string) (result *Destination, err error) {
	result = new(Destination)
	var kv struct {
		Key   string
		Value []byte
	}
	err = ms.db.C(colDst).Find(bson.M{"key": key}).One(&kv)
	if err == nil {
		b := bytes.NewBuffer(kv.Value)
		r, err := zlib.NewReader(b)
		if err != nil {
			return nil, err
		}
		out, err := ioutil.ReadAll(r)
		if err != nil {
			return nil, err
		}
		r.Close()
		err = ms.ms.Unmarshal(out, &result)
		if err != nil {
			return nil, err
		}
		// create optimized structure
		for _, p := range result.Prefixes {
			cache2go.Push(utils.DESTINATION_PREFIX+p, result.Id)
		}
	}
	if err != nil {
		result = nil
	}
	return
}
Exemplo n.º 3
0
func (al *Alias) SetReverseCache() {
	for _, value := range al.Values {
		for target, pairs := range value.Pairs {
			for _, alias := range pairs {
				rKey := strings.Join([]string{utils.REVERSE_ALIASES_PREFIX, alias, target, al.Context}, "")
				cache2go.Push(rKey, utils.ConcatenatedKey(al.GetId(), value.DestinationId))
			}
		}
	}
}
Exemplo n.º 4
0
func (ms *MongoStorage) GetDestination(key string) (result *Destination, err error) {
	result = new(Destination)
	err = ms.db.C(colDst).Find(bson.M{"id": key}).One(result)
	if err != nil {
		result = nil
		return
	}
	// create optimized structure
	for _, p := range result.Prefixes {
		cache2go.Push(utils.DESTINATION_PREFIX+p, result.Id)
	}
	return
}
Exemplo n.º 5
0
func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error) {
	key = utils.DESTINATION_PREFIX + key
	if values, ok := ms.dict[key]; ok {
		b := bytes.NewBuffer(values)
		r, err := zlib.NewReader(b)
		if err != nil {
			return nil, err
		}
		out, err := ioutil.ReadAll(r)
		if err != nil {
			return nil, err
		}
		r.Close()
		dest = new(Destination)
		err = ms.ms.Unmarshal(out, dest)
		// create optimized structure
		for _, p := range dest.Prefixes {
			cache2go.Push(utils.DESTINATION_PREFIX+p, dest.Id)
		}
	} else {
		return nil, utils.ErrNotFound
	}
	return
}