github.com/quite/nomad@v0.8.6/command/agent/search_endpoint.go (about) 1 package agent 2 3 import ( 4 "net/http" 5 6 "github.com/hashicorp/nomad/nomad/structs" 7 ) 8 9 // SearchRequest accepts a prefix and context and returns a list of matching 10 // IDs for that context. 11 func (s *HTTPServer) SearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { 12 if req.Method == "POST" || req.Method == "PUT" { 13 return s.newSearchRequest(resp, req) 14 } 15 return nil, CodedError(405, ErrInvalidMethod) 16 } 17 18 func (s *HTTPServer) newSearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { 19 args := structs.SearchRequest{} 20 21 if err := decodeBody(req, &args); err != nil { 22 return nil, CodedError(400, err.Error()) 23 } 24 25 if s.parse(resp, req, &args.Region, &args.QueryOptions) { 26 return nil, nil 27 } 28 29 var out structs.SearchResponse 30 if err := s.agent.RPC("Search.PrefixSearch", &args, &out); err != nil { 31 return nil, err 32 } 33 34 setMeta(resp, &out.QueryMeta) 35 return out, nil 36 }