-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
54 lines (41 loc) · 915 Bytes
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package es
import (
"net/url"
)
type API interface {
Path() string
Query() url.Values
}
type baseAPI struct {
Queries url.Values
}
func NewBaseAPI() *baseAPI {
return &baseAPI{url.Values{}}
}
func (api *baseAPI) Path() string {
return ""
}
func (api *baseAPI) Query() url.Values {
return api.Queries
}
func (api *baseAPI) singleOption(key, value string) {
api.Queries[key] = []string{value}
}
func (api *baseAPI) Pretty() {
api.singleOption("pretty", "true")
}
func (api *baseAPI) YAML() {
api.singleOption("format", "yaml")
}
func (api *baseAPI) MachineReadable() {
api.singleOption("human", "false")
}
func (api *baseAPI) AddFilterPath(paths ...string) {
api.Queries["filter_path"] = append(api.Queries["filter_path"], paths...)
}
func (api *baseAPI) FlatSettings() {
api.singleOption("flat_settings", "true")
}
func (api *baseAPI) CamelCase() {
api.singleOption("camelCase", "true")
}