2017-08-10 19:24:11 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2017-08-14 13:34:31 +00:00
|
|
|
"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-14 18:51:32 +00:00
|
|
|
// PrefixSearch returns a list of matches for a particular context and prefix.
|
2017-08-14 13:34:31 +00:00
|
|
|
func (s *Search) PrefixSearch(prefix string, context contexts.Context) (*SearchResponse, error) {
|
2017-08-11 21:21:35 +00:00
|
|
|
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
|
2017-08-14 13:34:31 +00:00
|
|
|
Context contexts.Context
|
2017-08-11 21:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SearchResponse struct {
|
2017-08-14 13:34:31 +00:00
|
|
|
Matches map[contexts.Context][]string
|
|
|
|
Truncations map[contexts.Context]bool
|
2017-08-11 21:21:35 +00:00
|
|
|
QueryMeta
|
|
|
|
}
|