diff --git a/client/keys.go b/client/keys.go index 71852a6ac..3f99453ba 100644 --- a/client/keys.go +++ b/client/keys.go @@ -234,6 +234,9 @@ type Node struct { // Key represents the unique location of this Node (e.g. "/foo/bar"). Key string `json:"key"` + // Dir reports whether node describes a directory. + Dir bool `json:"dir,omitempty"` + // Value is the current data stored on this Node. If this Node // is a directory, Value will be empty. Value string `json:"value"` @@ -248,10 +251,16 @@ type Node struct { // ModifiedIndex is the etcd index at-which this Node was last modified. ModifiedIndex uint64 `json:"modifiedIndex"` + + // Expiration is the server side expiration time of the key. + Expiration *time.Time `json:"expiration,omitempty"` + + // TTL is the time to live of the key in second. + TTL int64 `json:"ttl,omitempty"` } func (n *Node) String() string { - return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex) + return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d, TTL: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex, n.TTL) } type httpKeysAPI struct { diff --git a/client/keys_test.go b/client/keys_test.go index 147f18c04..06ece8299 100644 --- a/client/keys_test.go +++ b/client/keys_test.go @@ -483,6 +483,9 @@ func assertRequest(got http.Request, wantMethod string, wantURL *url.URL, wantHe } func TestUnmarshalSuccessfulResponse(t *testing.T) { + var expiration time.Time + expiration.UnmarshalText([]byte("2015-04-07T04:40:23.044979686Z")) + tests := []struct { hdr string body string @@ -518,7 +521,7 @@ func TestUnmarshalSuccessfulResponse(t *testing.T) { // Node { hdr: "15", - body: `{"action":"get", "node": {"key": "/foo", "value": "bar", "modifiedIndex": 12, "createdIndex": 10}}`, + body: `{"action":"get", "node": {"key": "/foo", "value": "bar", "modifiedIndex": 12, "createdIndex": 10, "ttl": 10, "expiration": "2015-04-07T04:40:23.044979686Z"}}`, wantRes: &Response{ Action: "get", Index: 15, @@ -527,6 +530,26 @@ func TestUnmarshalSuccessfulResponse(t *testing.T) { Value: "bar", ModifiedIndex: 12, CreatedIndex: 10, + TTL: 10, + Expiration: &expiration, + }, + PrevNode: nil, + }, + wantErr: false, + }, + + // Node Dir + { + hdr: "15", + body: `{"action":"get", "node": {"key": "/foo", "dir": true, "modifiedIndex": 12, "createdIndex": 10}}`, + wantRes: &Response{ + Action: "get", + Index: 15, + Node: &Node{ + Key: "/foo", + Dir: true, + ModifiedIndex: 12, + CreatedIndex: 10, }, PrevNode: nil, },