-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
issue_customfields.go
51 lines (45 loc) · 961 Bytes
/
issue_customfields.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
package redmine
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
)
type customFieldsResult struct {
CustomFields []CustomField `json:"custom_fields"`
}
// CustomFields consulta los campos personalizados
func (c *Client) CustomFields() ([]CustomField, error) {
req, err := http.NewRequest(
"GET",
fmt.Sprintf("%s/custom_fields.json?%s",
c.endpoint,
c.getPaginationClause()),
nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Redmine-API-Key", c.apikey)
res, err := c.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
var r customFieldsResult
if res.StatusCode != 200 {
var er errorsResult
err = decoder.Decode(&er)
if err == nil {
err = errors.New(strings.Join(er.Errors, "\n"))
}
} else {
err = decoder.Decode(&r)
}
if err != nil {
return nil, err
}
return r.CustomFields, nil
}