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