open-nomad/api/search.go

39 lines
800 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.
2017-08-14 13:34:31 +00:00
func (s *Search) PrefixSearch(prefix string, context contexts.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
}
type SearchRequest struct {
Prefix string
2017-08-14 13:34:31 +00:00
Context contexts.Context
}
type SearchResponse struct {
2017-08-14 13:34:31 +00:00
Matches map[contexts.Context][]string
Truncations map[contexts.Context]bool
QueryMeta
}