diff --git a/pkg/experiment/local/client.go b/pkg/experiment/local/client.go index 5552adc..73a1d69 100644 --- a/pkg/experiment/local/client.go +++ b/pkg/experiment/local/client.go @@ -54,7 +54,7 @@ func Initialize(apiKey string, config *Config) *Client { } } cohortStorage := newInMemoryCohortStorage() - flagConfigStorage := NewInMemoryFlagConfigStorage() + flagConfigStorage := newInMemoryFlagConfigStorage() var cohortLoader *cohortLoader var deploymentRunner *deploymentRunner if config.CohortSyncConfig != nil { @@ -362,7 +362,7 @@ func (c *Client) enrichUser(user *experiment.User, flagConfigs map[string]*evalu continue } if cohortIDs, ok := groupedCohortIDs[groupType]; ok { - user.AddGroupCohortIDs(groupType, groupName, c.cohortStorage.getCohortsForGroup(groupType, groupName, cohortIDs)) + user.AddGroupCohortIds(groupType, groupName, c.cohortStorage.getCohortsForGroup(groupType, groupName, cohortIDs)) } } } diff --git a/pkg/experiment/local/deployment_runner.go b/pkg/experiment/local/deployment_runner.go index cf82a2f..0f7b133 100644 --- a/pkg/experiment/local/deployment_runner.go +++ b/pkg/experiment/local/deployment_runner.go @@ -73,7 +73,7 @@ func (dr *deploymentRunner) periodicRefresh() error { func (dr *deploymentRunner) updateFlagConfigs() error { dr.log.Debug("Refreshing flag configs.") - flagConfigs, err := dr.flagConfigApi.GetFlagConfigs() + flagConfigs, err := dr.flagConfigApi.getFlagConfigs() if err != nil { dr.log.Error("Failed to fetch flag configs: %v", err) return err diff --git a/pkg/experiment/local/deployment_runner_test.go b/pkg/experiment/local/deployment_runner_test.go index 6eb59da..5c22064 100644 --- a/pkg/experiment/local/deployment_runner_test.go +++ b/pkg/experiment/local/deployment_runner_test.go @@ -17,7 +17,7 @@ func TestStartThrowsIfFirstFlagConfigLoadFails(t *testing.T) { return nil, errors.New("test") }} cohortDownloadAPI := &mockCohortDownloadApi{} - flagConfigStorage := NewInMemoryFlagConfigStorage() + flagConfigStorage := newInMemoryFlagConfigStorage() cohortStorage := newInMemoryCohortStorage() cohortLoader := newCohortLoader(cohortDownloadAPI, cohortStorage) @@ -43,7 +43,7 @@ func TestStartThrowsIfFirstCohortLoadFails(t *testing.T) { cohortDownloadAPI := &mockCohortDownloadApi{getCohortFunc: func(cohortID string, cohort *Cohort) (*Cohort, error) { return nil, errors.New("test") }} - flagConfigStorage := NewInMemoryFlagConfigStorage() + flagConfigStorage := newInMemoryFlagConfigStorage() cohortStorage := newInMemoryCohortStorage() cohortLoader := newCohortLoader(cohortDownloadAPI, cohortStorage) @@ -66,7 +66,7 @@ type mockFlagConfigApi struct { getFlagConfigsFunc func() (map[string]*evaluation.Flag, error) } -func (m *mockFlagConfigApi) GetFlagConfigs() (map[string]*evaluation.Flag, error) { +func (m *mockFlagConfigApi) getFlagConfigs() (map[string]*evaluation.Flag, error) { if m.getFlagConfigsFunc != nil { return m.getFlagConfigsFunc() } diff --git a/pkg/experiment/local/flag_config_api.go b/pkg/experiment/local/flag_config_api.go index d6ff58a..2964891 100644 --- a/pkg/experiment/local/flag_config_api.go +++ b/pkg/experiment/local/flag_config_api.go @@ -13,7 +13,7 @@ import ( ) type flagConfigApi interface { - GetFlagConfigs() (map[string]*evaluation.Flag, error) + getFlagConfigs() (map[string]*evaluation.Flag, error) } type flagConfigApiV2 struct { @@ -30,7 +30,7 @@ func newFlagConfigApiV2(deploymentKey, serverURL string, flagConfigPollerRequest } } -func (a *flagConfigApiV2) GetFlagConfigs() (map[string]*evaluation.Flag, error) { +func (a *flagConfigApiV2) getFlagConfigs() (map[string]*evaluation.Flag, error) { client := &http.Client{} endpoint, err := url.Parse("https://api.lab.amplitude.com/") if err != nil { diff --git a/pkg/experiment/local/flag_config_storage.go b/pkg/experiment/local/flag_config_storage.go index 69ad9d3..4635354 100644 --- a/pkg/experiment/local/flag_config_storage.go +++ b/pkg/experiment/local/flag_config_storage.go @@ -17,7 +17,7 @@ type inMemoryFlagConfigStorage struct { flagConfigsLock sync.Mutex } -func NewInMemoryFlagConfigStorage() *inMemoryFlagConfigStorage { +func newInMemoryFlagConfigStorage() *inMemoryFlagConfigStorage { return &inMemoryFlagConfigStorage{ flagConfigs: make(map[string]*evaluation.Flag), } diff --git a/pkg/experiment/local/flag_config_util.go b/pkg/experiment/local/flag_config_util.go index 2c4231e..d3fc46b 100644 --- a/pkg/experiment/local/flag_config_util.go +++ b/pkg/experiment/local/flag_config_util.go @@ -4,7 +4,6 @@ import ( "github.com/amplitude/experiment-go-server/internal/evaluation" ) -// isCohortFilter checks if the condition is a cohort filter. func isCohortFilter(condition *evaluation.Condition) bool { op := condition.Op selector := condition.Selector @@ -14,7 +13,6 @@ func isCohortFilter(condition *evaluation.Condition) bool { return false } -// getGroupedCohortConditionIDs extracts grouped cohort condition IDs from a segment. func getGroupedCohortConditionIDs(segment *evaluation.Segment) map[string]map[string]struct{} { cohortIDs := make(map[string]map[string]struct{}) if segment == nil { @@ -47,7 +45,6 @@ func getGroupedCohortConditionIDs(segment *evaluation.Segment) map[string]map[st return cohortIDs } -// getGroupedCohortIDsFromFlag extracts grouped cohort IDs from a flag. func getGroupedCohortIDsFromFlag(flag *evaluation.Flag) map[string]map[string]struct{} { cohortIDs := make(map[string]map[string]struct{}) for _, segment := range flag.Segments { @@ -63,7 +60,6 @@ func getGroupedCohortIDsFromFlag(flag *evaluation.Flag) map[string]map[string]st return cohortIDs } -// getAllCohortIDsFromFlag extracts all cohort IDs from a flag. func getAllCohortIDsFromFlag(flag *evaluation.Flag) map[string]struct{} { cohortIDs := make(map[string]struct{}) groupedIDs := getGroupedCohortIDsFromFlag(flag) @@ -75,7 +71,6 @@ func getAllCohortIDsFromFlag(flag *evaluation.Flag) map[string]struct{} { return cohortIDs } -// getGroupedCohortIDsFromFlags extracts grouped cohort IDs from multiple flags. func getGroupedCohortIDsFromFlags(flags []*evaluation.Flag) map[string]map[string]struct{} { cohortIDs := make(map[string]map[string]struct{}) for _, flag := range flags { @@ -91,7 +86,6 @@ func getGroupedCohortIDsFromFlags(flags []*evaluation.Flag) map[string]map[strin return cohortIDs } -// getAllCohortIDsFromFlags extracts all cohort IDs from multiple flags. func getAllCohortIDsFromFlags(flags []*evaluation.Flag) map[string]struct{} { cohortIDs := make(map[string]struct{}) for _, flag := range flags { @@ -102,7 +96,6 @@ func getAllCohortIDsFromFlags(flags []*evaluation.Flag) map[string]struct{} { return cohortIDs } -// helper function to check if selector contains groups func selectorContainsGroups(selector []string) bool { for _, s := range selector { if s == "groups" { diff --git a/pkg/experiment/types.go b/pkg/experiment/types.go index 19c465a..378b319 100644 --- a/pkg/experiment/types.go +++ b/pkg/experiment/types.go @@ -28,7 +28,7 @@ type User struct { lock sync.Mutex } -func (u *User) AddGroupCohortIDs(groupType, groupName string, cohortIDs map[string]struct{}) { +func (u *User) AddGroupCohortIds(groupType, groupName string, cohortIds map[string]struct{}) { u.lock.Lock() defer u.lock.Unlock() @@ -42,7 +42,7 @@ func (u *User) AddGroupCohortIDs(groupType, groupName string, cohortIDs map[stri u.GroupCohortIds[groupType] = groupNames } - groupNames[groupName] = cohortIDs + groupNames[groupName] = cohortIds } type Variant struct {