Beispiel #1
0
func set(client keyvalue.TChanKeyValue, key, value string) {
	ctx, cancel := createContext()
	defer cancel()

	if err := client.Set(ctx, key, value); err != nil {
		switch err := err.(type) {
		case *keyvalue.InvalidKey:
			log.Printf("Set %v failed: invalid key", key)
		default:
			log.Printf("Set %v:%v failed unexpectedly: %#v", key, value, err)
		}
		return
	}

	log.Printf("Set %v:%v succeeded with headers: %v", key, value, ctx.ResponseHeaders())
}
Beispiel #2
0
func get(client keyvalue.TChanKeyValue, key string) {
	ctx, cancel := createContext()
	defer cancel()

	val, err := client.Get(ctx, key)
	if err != nil {
		switch err := err.(type) {
		case *keyvalue.InvalidKey:
			log.Printf("Get %v failed: invalid key", key)
		case *keyvalue.KeyNotFound:
			log.Printf("Get %v failed: key not found", key)
		default:
			log.Printf("Get %v failed unexpectedly: %v", key, err)
		}
		return
	}

	log.Printf("Get %v: %v", key, val)
}