Beispiel #1
0
func (p *DatabaseStore) Set(key string, val interface{}, encrypt bool) error {
	buf, err := utils.ToJson(val)
	if err != nil {
		return err
	}
	if encrypt {
		buf, err = p.Aes.Encrypt(buf)
		if err != nil {
			return err
		}
	}

	row := p.Db.Get("settings.count", key)

	var c int

	if err = row.Scan(&c); err != nil {
		return err
	}
	if c > 0 {
		_, err = p.Db.Exec("settings.update", encrypt, buf, key)
	} else {
		_, err = p.Db.Exec("settings.add", key, encrypt, buf)

	}
	return err
}
Beispiel #2
0
func NewMessage(args ...interface{}) (*Message, error) {
	buf, err := utils.ToJson(args)
	if err != nil {
		return nil, err
	}
	return &Message{
		Id:      utils.Uuid(),
		Body:    buf,
		Created: time.Now(),
	}, nil
}
Beispiel #3
0
func (p *RedisStore) Push(queue string, msg *Message) error {
	c := p.pool.Get()
	defer c.Close()
	buf, err := utils.ToJson(msg)
	if err != nil {
		return err
	}

	_, err = c.Do("LPUSH", p.queue(queue), buf)
	return err

}
Beispiel #4
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)
	}
}