open-nomad/api/search.go

40 lines
854 B
Go
Raw Normal View History

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.
func (s *Search) PrefixSearch(prefix string, context contexts.Context, q *QueryOptions) (*SearchResponse, *QueryMeta, error) {
var resp SearchResponse
req := &SearchRequest{Prefix: prefix, Context: context}
2017-08-10 19:24:11 +00:00
qm, err := s.client.putQuery("/v1/search", req, &resp, q)
2017-08-10 19:24:11 +00:00
if err != nil {
return nil, nil, err
2017-08-10 19:24:11 +00:00
}
return &resp, qm, nil
2017-08-10 19:24:11 +00:00
}
type SearchRequest struct {
Prefix string
2017-08-14 13:34:31 +00:00
Context contexts.Context
QueryOptions
}
type SearchResponse struct {
2017-08-14 13:34:31 +00:00
Matches map[contexts.Context][]string
Truncations map[contexts.Context]bool
QueryMeta
}