Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
davidji99 committed Mar 18, 2024
1 parent fe39161 commit 0fa933f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
4 changes: 3 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Client struct {
ApiKeys *KeysService
Attributes *AttributesService
Environments *EnvironmentsService
FeatureFlags *FeatureFlagsService
Groups *GroupsService
TrafficTypes *TrafficTypesService
Segments *SegmentsService
Expand Down Expand Up @@ -119,6 +120,7 @@ func (c *Client) injectServices() {
c.ApiKeys = (*KeysService)(&c.common)
c.Attributes = (*AttributesService)(&c.common)
c.Environments = (*EnvironmentsService)(&c.common)
c.FeatureFlags = (*FeatureFlagsService)(&c.common)
c.Groups = (*GroupsService)(&c.common)
c.TrafficTypes = (*TrafficTypesService)(&c.common)
c.Segments = (*SegmentsService)(&c.common)
Expand All @@ -143,7 +145,7 @@ func (c *Client) setHeaders() {

func (c *Client) checkRateLimit(resp *simpleresty.Response) bool {
if resp != nil && resp.StatusCode == 429 {
remainingOrgSeconds, _ := strconv.Atoi((resp.Resp.Header().Get("X-RateLimit-Reset-Seconds-Org")))
remainingOrgSeconds, _ := strconv.Atoi(resp.Resp.Header().Get("X-RateLimit-Reset-Seconds-Org"))
timeToSleep, _ := strconv.Atoi(resp.Resp.Header().Get("X-RateLimit-Reset-Seconds-IP"))
if remainingOrgSeconds != 0 {
// Got rate-limit by Organization
Expand Down
50 changes: 50 additions & 0 deletions api/feature_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package api

import (
"fmt"
"github.com/davidji99/simpleresty"
)

// FeatureFlagsService handles communication with the environments related
// methods of the Split.io APIv2.
//
// Reference: https://docs.split.io/reference/feature-flag-overview
type FeatureFlagsService service

// FeatureFlag represents a feature flag in Split.
type FeatureFlag struct {
ID *string `json:"id"`
Name *string `json:"name"`
Description *string `json:"description"`
TrafficType *TrafficType `json:"trafficType"`
CreationTime *int64 `json:"creationTime"`
Tags []*Tag `json:"tags"`
}

// FeatureFlagsListResponse represents the response when listing feature flags.
type FeatureFlagsListResponse struct {
GenericListResult
FeatureFlags []*FeatureFlag `json:"objects"`
}

type FeatureFlagsListOpts struct {
GenericListQueryParams

// Tags are repeatable tag parameter(s) to query by
Tags []string `url:"tags,omitempty"`
}

// List all feature flags.
//
// Reference: https://docs.split.io/reference/list-feature-flags
func (f *FeatureFlagsService) List(workspaceID string, opts *FeatureFlagsListOpts) (*FeatureFlagsListResponse, *simpleresty.Response, error) {
var result FeatureFlagsListResponse
urlStr, err := f.client.http.RequestURLWithQueryParams(fmt.Sprintf("/splits/ws/%s", workspaceID), opts)
if err != nil {
return nil, nil, err
}

response, getErr := f.client.get(urlStr, &result, nil)

return &result, response, getErr
}
1 change: 0 additions & 1 deletion api/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ type WorkspaceListQueryParams struct {
// Reference: https://docs.split.io/reference#get-workspaces
func (w *WorkspacesService) List(opts ...interface{}) (*Workspaces, *simpleresty.Response, error) {
var result *Workspaces
//
urlStr, err := w.client.http.RequestURLWithQueryParams("/workspaces", opts...)
if err != nil {
return nil, nil, err
Expand Down

0 comments on commit 0fa933f

Please sign in to comment.