Пример #1
0
func TestJson(t *testing.T) {
	if jsn, err := ks.ToJson(obj); err == nil {
		t.Logf("TO JSON: %v", jsn)
		var obj1 = make(map[string]interface{}, 0)
		if err := ks.FromJson(jsn, &obj1); err == nil && obj["value"] == obj1["value"] {
			t.Logf("FROM JSON: %v", obj1)
		} else {
			t.Errorf("From json error! %v VS %v", obj, obj1)
		}
	} else {
		t.Errorf("To json error! %v", err)
	}
}
Пример #2
0
func (p *DatabaseStore) Get(key string, val interface{}) error {
	row := p.Db.Get("settings.get", key)

	var buf []byte
	var enc bool

	err := row.Scan(&enc, &buf)
	if err != nil {
		return err
	}
	if enc {
		buf, err = p.Aes.Decrypt(buf)
		if err != nil {
			return err
		}
	}
	return utils.FromJson(buf, val)

}
Пример #3
0
func (p *RedisStore) Pop(timeout time.Duration, queues ...string) (string, *Message, error) {
	c := p.pool.Get()
	defer c.Close()

	args := make([]interface{}, 0)
	for _, q := range queues {
		args = append(args, p.queue(q))
	}
	args = append(args, int(timeout.Seconds()))

	rep, err := redis.Values(c.Do("BRPOP", args...))
	if err != nil {
		return "", nil, err
	}

	name := string(rep[0].([]byte)[6:])
	msg := Message{}
	err = utils.FromJson(rep[1].([]byte), &msg)
	if err != nil {
		return "", nil, err
	}
	return name, &msg, nil

}
Пример #4
0
func (p *Message) Parse(args ...interface{}) error {
	return utils.FromJson(p.Body, &args)
}