瀏覽代碼

client: encourage error handling in package doc

Brian Waldon 11 年之前
父節點
當前提交
2b5589ddcd
共有 1 個文件被更改,包括 8 次插入2 次删除
  1. 8 2
      client/doc.go

+ 8 - 2
client/doc.go

@@ -39,10 +39,16 @@ Create a KeysAPI using the Client, then use it to interact with etcd:
 	kAPI := client.NewKeysAPI(c)
 
 	// create a new key /foo with the value "bar"
-	kAPI.Create(context.Background(), "/foo", "bar")
+	_, err = kAPI.Create(context.Background(), "/foo", "bar")
+	if err != nil {
+		// handle error
+	}
 
 	// delete the newly created key only if the value is still "bar"
-	kAPI.Delete(context.Background(), "/foo", &DeleteOptions{PrevValue: "bar"})
+	_, err = kAPI.Delete(context.Background(), "/foo", &DeleteOptions{PrevValue: "bar"})
+	if err != nil {
+		// handle error
+	}
 
 Use a custom context to set timeouts on your operations: