@@ -4,18 +4,19 @@ import (
4
4
"bytes"
5
5
"encoding/json"
6
6
"fmt"
7
- "io/ioutil "
7
+ "io"
8
8
"net/http"
9
9
"strings"
10
10
)
11
11
12
12
// Client token, host, htpp.Client
13
13
type Client struct {
14
- Token string
15
- TokenHeader string
16
- Host string
17
- HostV2 string
18
- Client * http.Client
14
+ Token string
15
+ TokenHeader string
16
+ Host string
17
+ HostV2 string
18
+ featureFlags map [string ]bool
19
+ Client * http.Client
19
20
}
20
21
21
22
// RequestOptions path, method, etc
@@ -35,11 +36,12 @@ func NewClient(hostname string, hostnameV2 string, token string, tokenHeader str
35
36
tokenHeader = "Authorization"
36
37
}
37
38
return & Client {
38
- Host : hostname ,
39
- HostV2 : hostnameV2 ,
40
- Token : token ,
41
- TokenHeader : tokenHeader ,
42
- Client : & http.Client {},
39
+ Host : hostname ,
40
+ HostV2 : hostnameV2 ,
41
+ Token : token ,
42
+ TokenHeader : tokenHeader ,
43
+ Client : & http.Client {},
44
+ featureFlags : map [string ]bool {},
43
45
}
44
46
45
47
}
@@ -69,7 +71,7 @@ func (client *Client) RequestAPI(opt *RequestOptions) ([]byte, error) {
69
71
}
70
72
defer resp .Body .Close ()
71
73
72
- body , err := ioutil .ReadAll (resp .Body )
74
+ body , err := io .ReadAll (resp .Body )
73
75
if err != nil {
74
76
return nil , fmt .Errorf ("Failed to read body %v %v" , resp .StatusCode , resp .Status )
75
77
}
@@ -101,7 +103,7 @@ func (client *Client) RequestApiXAccessToken(opt *RequestOptions) ([]byte, error
101
103
}
102
104
defer resp .Body .Close ()
103
105
104
- body , err := ioutil .ReadAll (resp .Body )
106
+ body , err := io .ReadAll (resp .Body )
105
107
if err != nil {
106
108
return nil , fmt .Errorf ("Failed to read body %v %v" , resp .StatusCode , resp .Status )
107
109
}
@@ -112,6 +114,25 @@ func (client *Client) RequestApiXAccessToken(opt *RequestOptions) ([]byte, error
112
114
return body , nil
113
115
}
114
116
117
+ func (client * Client ) isFeatureFlagEnabled (flagName string ) (bool , error ) {
118
+
119
+ if len (client .featureFlags ) == 0 {
120
+ currAcc , err := client .GetCurrentAccount ()
121
+
122
+ if err != nil {
123
+ return false , err
124
+ }
125
+
126
+ client .featureFlags = currAcc .FeatureFlags
127
+ }
128
+
129
+ if val , ok := client .featureFlags [flagName ]; ok {
130
+ return val , nil
131
+ }
132
+
133
+ return false , nil
134
+ }
135
+
115
136
// ToQS add extra parameters to path
116
137
func ToQS (qs map [string ]string ) string {
117
138
var arr = []string {}
0 commit comments