From e5c7effaa941c7a467cdbe4d5bd7481f1747e3b5 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 7 Sep 2015 10:03:10 -0700 Subject: [PATCH] http: list results are never null --- command/agent/alloc_endpoint.go | 3 +++ command/agent/eval_endpoint.go | 6 ++++++ command/agent/job_endpoint.go | 9 +++++++++ command/agent/node_endpoint.go | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index ce9da1ecc..7668bfd85 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -23,6 +23,9 @@ func (s *HTTPServer) AllocsRequest(resp http.ResponseWriter, req *http.Request) } setMeta(resp, &out.QueryMeta) + if out.Allocations == nil { + out.Allocations = make([]*structs.AllocListStub, 0) + } return out.Allocations, nil } diff --git a/command/agent/eval_endpoint.go b/command/agent/eval_endpoint.go index 32cddcd16..56c646bd2 100644 --- a/command/agent/eval_endpoint.go +++ b/command/agent/eval_endpoint.go @@ -23,6 +23,9 @@ func (s *HTTPServer) EvalsRequest(resp http.ResponseWriter, req *http.Request) ( } setMeta(resp, &out.QueryMeta) + if out.Evaluations == nil { + out.Evaluations = make([]*structs.Evaluation, 0) + } return out.Evaluations, nil } @@ -55,6 +58,9 @@ func (s *HTTPServer) evalAllocations(resp http.ResponseWriter, req *http.Request } setMeta(resp, &out.QueryMeta) + if out.Allocations == nil { + out.Allocations = make([]*structs.AllocListStub, 0) + } return out.Allocations, nil } diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index cdbb6ac7e..4812ee08f 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -30,6 +30,9 @@ func (s *HTTPServer) jobListRequest(resp http.ResponseWriter, req *http.Request) } setMeta(resp, &out.QueryMeta) + if out.Jobs == nil { + out.Jobs = make([]*structs.JobListStub, 0) + } return out.Jobs, nil } @@ -86,6 +89,9 @@ func (s *HTTPServer) jobAllocations(resp http.ResponseWriter, req *http.Request, } setMeta(resp, &out.QueryMeta) + if out.Allocations == nil { + out.Allocations = make([]*structs.AllocListStub, 0) + } return out.Allocations, nil } @@ -107,6 +113,9 @@ func (s *HTTPServer) jobEvaluations(resp http.ResponseWriter, req *http.Request, } setMeta(resp, &out.QueryMeta) + if out.Evaluations == nil { + out.Evaluations = make([]*structs.Evaluation, 0) + } return out.Evaluations, nil } diff --git a/command/agent/node_endpoint.go b/command/agent/node_endpoint.go index 020637759..c872912e0 100644 --- a/command/agent/node_endpoint.go +++ b/command/agent/node_endpoint.go @@ -24,6 +24,9 @@ func (s *HTTPServer) NodesRequest(resp http.ResponseWriter, req *http.Request) ( } setMeta(resp, &out.QueryMeta) + if out.Nodes == nil { + out.Nodes = make([]*structs.NodeListStub, 0) + } return out.Nodes, nil } @@ -80,6 +83,9 @@ func (s *HTTPServer) nodeAllocations(resp http.ResponseWriter, req *http.Request } setMeta(resp, &out.QueryMeta) + if out.Allocs == nil { + out.Allocs = make([]*structs.Allocation, 0) + } return out.Allocs, nil }