2017-08-10 19:24:11 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2017-08-11 13:33:00 +00:00
|
|
|
c "github.com/hashicorp/nomad/api/contexts"
|
2017-08-10 19:24:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Search struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search returns a handle on the Search endpoints
|
|
|
|
func (c *Client) Search() *Search {
|
|
|
|
return &Search{client: c}
|
|
|
|
}
|
|
|
|
|
2017-08-11 13:33:00 +00:00
|
|
|
// PrefixSearch returns a list of matches for a particular context and prefix. If a
|
2017-08-10 19:24:11 +00:00
|
|
|
// context is not specified, matches for all contexts are returned.
|
2017-08-11 21:21:35 +00:00
|
|
|
func (s *Search) PrefixSearch(prefix string, context c.Context) (*SearchResponse, error) {
|
|
|
|
var resp SearchResponse
|
|
|
|
req := &SearchRequest{Prefix: prefix, Context: context}
|
2017-08-10 19:24:11 +00:00
|
|
|
|
|
|
|
_, err := s.client.write("/v1/search", req, &resp, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &resp, nil
|
|
|
|
}
|
2017-08-11 21:21:35 +00:00
|
|
|
|
|
|
|
type SearchRequest struct {
|
|
|
|
Prefix string
|
|
|
|
Context c.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
type SearchResponse struct {
|
|
|
|
Matches map[c.Context][]string
|
|
|
|
Truncations map[c.Context]bool
|
|
|
|
QueryMeta
|
|
|
|
}
|