@@ -4,18 +4,19 @@ import (
44 "bytes"
55 "encoding/json"
66 "fmt"
7- "io/ioutil "
7+ "io"
88 "net/http"
99 "strings"
1010)
1111
1212// Client token, host, htpp.Client
1313type 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
1920}
2021
2122// RequestOptions path, method, etc
@@ -35,11 +36,12 @@ func NewClient(hostname string, hostnameV2 string, token string, tokenHeader str
3536 tokenHeader = "Authorization"
3637 }
3738 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 {},
4345 }
4446
4547}
@@ -69,7 +71,7 @@ func (client *Client) RequestAPI(opt *RequestOptions) ([]byte, error) {
6971 }
7072 defer resp .Body .Close ()
7173
72- body , err := ioutil .ReadAll (resp .Body )
74+ body , err := io .ReadAll (resp .Body )
7375 if err != nil {
7476 return nil , fmt .Errorf ("Failed to read body %v %v" , resp .StatusCode , resp .Status )
7577 }
@@ -101,7 +103,7 @@ func (client *Client) RequestApiXAccessToken(opt *RequestOptions) ([]byte, error
101103 }
102104 defer resp .Body .Close ()
103105
104- body , err := ioutil .ReadAll (resp .Body )
106+ body , err := io .ReadAll (resp .Body )
105107 if err != nil {
106108 return nil , fmt .Errorf ("Failed to read body %v %v" , resp .StatusCode , resp .Status )
107109 }
@@ -112,6 +114,25 @@ func (client *Client) RequestApiXAccessToken(opt *RequestOptions) ([]byte, error
112114 return body , nil
113115}
114116
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+
115136// ToQS add extra parameters to path
116137func ToQS (qs map [string ]string ) string {
117138 var arr = []string {}
0 commit comments