-
Notifications
You must be signed in to change notification settings - Fork 6
tested and added root org support #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chandrajeetn
wants to merge
5
commits into
LambdaTest:main
Choose a base branch
from
chandrajeetn:CBT-20325
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
vendor/ | ||
.idea/ | ||
.vscode/ | ||
.DS_Store | ||
internal/.DS_Store | ||
local_evaluation.go |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package model | ||
|
||
type OrgId int64 | ||
|
||
type OrgMap map[OrgId]OrgId | ||
|
||
// ErrorResponse represents the error response from the LUMS API | ||
type ErrorResponse struct { | ||
Type string `json:"type"` | ||
Title string `json:"title"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// SuccessResponse represents the success response from the LUMS API | ||
type SuccessResponse struct { | ||
Type string `json:"type"` | ||
Data OrgMap `json:"data"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package rootOrg | ||
|
||
import ( | ||
"strconv" | ||
"sync" | ||
|
||
"github.com/LambdaTest/lambda-featureflag-go-sdk/model" | ||
) | ||
|
||
type Client struct { | ||
apiKey string | ||
Config *Config | ||
poller *poller | ||
flags *model.OrgMap | ||
flagsMutex *sync.RWMutex | ||
} | ||
|
||
func NewClient(apiKey string, config *Config) *Client { | ||
return &Client{ | ||
apiKey: apiKey, | ||
Config: config, | ||
flagsMutex: &sync.RWMutex{}, | ||
flags: &model.OrgMap{}, | ||
poller: newPoller(), | ||
} | ||
} | ||
|
||
func (c *Client) Start() error { | ||
c.poller = newPoller() | ||
c.poller.Poll(c.Config.FlagConfigPollerInterval, func() { | ||
c.pollFlags() | ||
}) | ||
return c.pollFlags() | ||
} | ||
|
||
func (c *Client) Stop() { | ||
close(c.poller.shutdown) | ||
} | ||
|
||
func (c *Client) pollFlags() error { | ||
c.flagsMutex.Lock() | ||
defer c.flagsMutex.Unlock() | ||
rootOrgs, err := GetRootOrgs(c.apiKey, c.Config.ServerUrl, c.Config.FlagConfigPollerRequestTimeout) | ||
if err != nil { | ||
return err | ||
} | ||
c.flags = rootOrgs | ||
return nil | ||
} | ||
|
||
func (c *Client) Evaluate(orgId any) (any, bool) { | ||
c.flagsMutex.RLock() | ||
defer c.flagsMutex.RUnlock() | ||
|
||
orgIdStr, _ := orgId.(string) | ||
orgIdInt, _ := strconv.ParseInt(orgIdStr, 10, 64) | ||
chandrajeetn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
org, ok := (*c.flags)[model.OrgId(orgIdInt)] | ||
return org, ok | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package rootOrg | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type Config struct { | ||
ServerUrl string | ||
FlagConfigPollerInterval time.Duration | ||
FlagConfigPollerRequestTimeout time.Duration | ||
} | ||
|
||
var DefaultConfig = &Config{ | ||
ServerUrl: "https://api.lambdatest.com", | ||
FlagConfigPollerInterval: 120 * time.Second, | ||
FlagConfigPollerRequestTimeout: 60 * time.Second, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package rootOrg | ||
|
||
import "time" | ||
|
||
type poller struct { | ||
shutdown chan bool | ||
} | ||
|
||
func newPoller() *poller { | ||
return &poller{ | ||
shutdown: make(chan bool), | ||
chandrajeetn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
func (p *poller) Poll(interval time.Duration, function func()) { | ||
ticker := time.NewTicker(interval) | ||
go func() { | ||
for { | ||
select { | ||
case <-p.shutdown: | ||
ticker.Stop() | ||
return | ||
case <-ticker.C: | ||
go function() | ||
} | ||
} | ||
}() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.