Test Setup Failed
Pull Request — master (#2)
by Adriano
01:24
created

solr/config.go   A

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 56
dl 0
loc 92
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A solr.*ConfigAPI.List 0 14 3
A solr.*ConfigAPI.Create 0 14 3
A solr.*ConfigAPI.Delete 0 16 3
A solr.*ConfigAPI.Upload 0 10 2
1
package solr
2
3
import (
4
	"context"
5
	"fmt"
6
	"net/http"
7
)
8
9
const (
10
	ActionUpload	=	"UPLOAD"
1 ignored issue
show
introduced by
exported const ActionUpload should have comment (or a comment on this block) or be unexported
Loading history...
11
)
12
13
type Config struct {
1 ignored issue
show
introduced by
exported type Config should have comment or be unexported
Loading history...
14
	Name 					string 		`json:"name,omitempty"url:"name,omitempty"`
1 ignored issue
show
introduced by
struct field tag json:"name,omitempty"url:"name,omitempty" not compatible with reflect.StructTag.Get: key:"value" pairs not separated by spaces
Loading history...
15
	BaseConfigSet 			string		`json:"baseConfigSet,omitempty"`
16
	ConfigSetPropImmutable 	bool		`json:"configSetProp.immutable,omitempty"`
17
}
18
19
type ConfigParameter struct {
1 ignored issue
show
introduced by
exported type ConfigParameter should have comment or be unexported
Loading history...
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
introduced by
exported type ConfigAPI should have comment or be unexported
Loading history...
26
	client 		*Client
27
}
28
29
type CreateConfig struct {
1 ignored issue
show
introduced by
exported type CreateConfig should have comment or be unexported
Loading history...
30
	Create			Config 		`json:"create,omitempty"`
31
}
32
33
func (c *ConfigAPI) List(ctx context.Context) (*Response, error) {
1 ignored issue
show
introduced by
exported method ConfigAPI.List should have comment or be unexported
Loading history...
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
introduced by
exported method ConfigAPI.Upload should have comment or be unexported
Loading history...
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
introduced by
exported method ConfigAPI.Create should have comment or be unexported
Loading history...
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
introduced by
exported method ConfigAPI.Delete should have comment or be unexported
Loading history...
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
}