diff --git a/api/api.go b/api/api.go index c92546b50c..fcb7c37306 100644 --- a/api/api.go +++ b/api/api.go @@ -111,6 +111,9 @@ type QueryOptions struct { // by the Config Datacenter string + // Providing a peer name in the query option + Peer string + // AllowStale allows any Consul server (non-leader) to service // a read. This allows for lower latency and higher throughput AllowStale bool @@ -812,6 +815,9 @@ func (r *request) setQueryOptions(q *QueryOptions) { if q.Datacenter != "" { r.params.Set("dc", q.Datacenter) } + if q.Peer != "" { + r.params.Set("peer", q.Peer) + } if q.AllowStale { r.params.Set("stale", "") } diff --git a/api/api_test.go b/api/api_test.go index a95a4044c5..3574240d1a 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -763,6 +763,7 @@ func TestAPI_SetQueryOptions(t *testing.T) { Namespace: "operator", Partition: "asdf", Datacenter: "foo", + Peer: "dc10", AllowStale: true, RequireConsistent: true, WaitIndex: 1000, @@ -779,6 +780,9 @@ func TestAPI_SetQueryOptions(t *testing.T) { if r.params.Get("partition") != "asdf" { t.Fatalf("bad: %v", r.params) } + if r.params.Get("peer") != "dc10" { + t.Fatalf("bad: %v", r.params) + } if r.params.Get("dc") != "foo" { t.Fatalf("bad: %v", r.params) }