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-28 05:17:51 +00:00
|
|
|
func (s *Search) PrefixSearch(prefix string, context contexts.Context, q *QueryOptions) (*SearchResponse, *QueryMeta, 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
|
|
|
|
2017-08-28 05:17:51 +00:00
|
|
|
qm, err := s.client.putQuery("/v1/search", req, &resp, q)
|
2017-08-10 19:24:11 +00:00
|
|
|
if err != nil {
|
2017-08-28 05:17:51 +00:00
|
|
|
return nil, nil, err
|
2017-08-10 19:24:11 +00:00
|
|
|
}
|
|
|
|
|
2017-08-28 05:17:51 +00:00
|
|
|
return &resp, qm, nil
|
2017-08-10 19:24:11 +00:00
|
|
|
}
|
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-28 05:17:51 +00:00
|
|
|
QueryOptions
|
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
|
|
|
|
}
|