1
|
|
|
package solr |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"fmt" |
6
|
|
|
"net/http" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
const ( |
10
|
|
|
ActionUpload = "UPLOAD" |
11
|
|
|
) |
12
|
|
|
|
13
|
|
|
type Config struct { |
14
|
|
|
Name string `json:"name,omitempty"url:"name,omitempty"` |
15
|
|
|
BaseConfigSet string `json:"baseConfigSet,omitempty"` |
16
|
|
|
ConfigSetPropImmutable bool `json:"configSetProp.immutable,omitempty"` |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
type ConfigParameter struct { |
20
|
|
|
Action string `url:"action,omitempty"` |
21
|
|
|
Name string `url:"name,omitempty"` |
22
|
|
|
OmitHeader bool `url:"omitHeader,omitempty"` |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
type ConfigAPI struct { |
26
|
|
|
client *Client |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
type CreateConfig struct { |
30
|
|
|
Create Config `json:"create,omitempty"` |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// LIST: List a Configset |
34
|
|
|
func (c *ConfigAPI) List(ctx context.Context) (*Response, error) { |
35
|
|
|
req, err := c.client.NewRequest(ctx, http.MethodGet, "/api/cluster/configs", nil, &ConfigParameter{ |
36
|
|
|
OmitHeader: true, |
37
|
|
|
}, nil) |
38
|
|
|
if err != nil { |
39
|
|
|
return nil, err |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
response, err := c.client.Do(ctx, req) |
43
|
|
|
if err != nil { |
44
|
|
|
return nil, err |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return response, err |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// UPLOAD: Upload a Configset |
51
|
|
|
func (c *ConfigAPI) Upload(ctx context.Context, filename string, name string) (*Response, error) { |
52
|
|
|
response, err := c.client.NewUpload(ctx, "/solr/admin/configs", filename, &ConfigParameter{ |
53
|
|
|
Action: ActionUpload, |
54
|
|
|
Name: name, |
55
|
|
|
}) |
56
|
|
|
if err != nil { |
57
|
|
|
return nil, err |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return response, err |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// CREATE: Create a Configset |
64
|
|
|
func (c *ConfigAPI) Create(ctx context.Context, config CreateConfig) (*Response, error) { |
65
|
|
|
req, err := c.client.NewRequest(ctx, http.MethodPost, "/api/cluster/configs", config, &ConfigParameter{ |
66
|
|
|
OmitHeader: true, |
67
|
|
|
}, nil) |
68
|
|
|
if err != nil { |
69
|
|
|
return nil, err |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
response, err := c.client.Do(ctx, req) |
73
|
|
|
if err != nil { |
74
|
|
|
return nil, err |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return response, err |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// DELETE: Create a Configset |
81
|
|
|
func (c *ConfigAPI) Delete(ctx context.Context, name string) (*Response, error) { |
82
|
|
|
path := fmt.Sprintf("/api/cluster/configs/%s", name) |
83
|
|
|
|
84
|
|
|
req, err := c.client.NewRequest(ctx, http.MethodDelete, path, nil, &ConfigParameter{ |
85
|
|
|
OmitHeader: true, |
86
|
|
|
}, nil) |
87
|
|
|
if err != nil { |
88
|
|
|
return nil, err |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
response, err := c.client.Do(ctx, req) |
92
|
|
|
if err != nil { |
93
|
|
|
return nil, err |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return response, err |
97
|
|
|
} |
98
|
|
|
|