...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 "net/url"
23 )
24
25
26
27
28
29 type FeaturesService struct {
30 client *Client
31 }
32
33
34
35
36 type Feature struct {
37 Name string `json:"name"`
38 State string `json:"state"`
39 Gates []Gate
40 }
41
42
43
44
45 type Gate struct {
46 Key string `json:"key"`
47 Value interface{} `json:"value"`
48 }
49
50 func (f Feature) String() string {
51 return Stringify(f)
52 }
53
54
55
56
57
58 func (s *FeaturesService) ListFeatures(options ...RequestOptionFunc) ([]*Feature, *Response, error) {
59 req, err := s.client.NewRequest(http.MethodGet, "features", nil, options)
60 if err != nil {
61 return nil, nil, err
62 }
63
64 var f []*Feature
65 resp, err := s.client.Do(req, &f)
66 if err != nil {
67 return nil, resp, err
68 }
69 return f, resp, nil
70 }
71
72
73
74
75
76 func (s *FeaturesService) SetFeatureFlag(name string, value interface{}, options ...RequestOptionFunc) (*Feature, *Response, error) {
77 u := fmt.Sprintf("features/%s", url.PathEscape(name))
78
79 opt := struct {
80 Value interface{} `url:"value" json:"value"`
81 }{
82 value,
83 }
84
85 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
86 if err != nil {
87 return nil, nil, err
88 }
89
90 f := &Feature{}
91 resp, err := s.client.Do(req, f)
92 if err != nil {
93 return nil, resp, err
94 }
95 return f, resp, nil
96 }
97
View as plain text