Exemple #1
0
func createAccessKey(token string, read, write []string, allowedUses int) error {
	r, err := redisurl.Connect()
	if err != nil {
		return err
	}
	defer r.Close()

	ak := &AccessKey{
		Token:       token,
		Read:        read,
		Write:       write,
		AllowedUses: allowedUses,
		Uses:        0,
	}

	data, err := json.Marshal(ak)
	if err != nil {
		return err
	}

	_, err = r.Do("SET", "philote:access_key:"+ak.Token, string(data))
	if err != nil {
		return err
	}

	return nil
}
Exemple #2
0
func publishMessage(channel, data string) (listeners int, err error) {
	message := &Message{
		Channel:  channel,
		Data:     data,
		Event:    "message",
		IssuerID: "philote-cli",
	}

	payload, err := json.Marshal(message)
	if err != nil {
		return
	}

	r, err := redisurl.Connect()
	if err != nil {
		return
	}
	defer r.Close()

	listeners, err = redis.Int(r.Do("PUBLISH", "philote:channel:"+channel, string(payload)))
	if err != nil {
		return
	}

	return
}