client: document using a custom context

release-2.1
Brian Waldon 2015-01-28 12:51:27 -08:00 committed by Yicheng Qin
parent 479a17dcbf
commit 6fd105d554
1 changed files with 17 additions and 0 deletions

View File

@ -44,5 +44,22 @@ Create a KeysAPI using the Client, then use it to interact with etcd:
// delete the newly created key only if the value is still "bar"
kAPI.Delete(context.Background(), "/foo", &DeleteOptions{PrevValue: "bar"})
Use a custom context to set timeouts on your operations:
import "time"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// set a new key, ignoring it's previous state
_, err := kAPI.Set(ctx, "/ping", "pong", nil)
if err != nil {
if err == context.DeadlineExceeded {
// request took longer than 5s
} else {
// handle error
}
}
*/
package client