Skip to content

Commit

Permalink
Fix class/method names
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Jul 3, 2024
1 parent 1afeeb9 commit 1df8194
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pkg/experiment/local/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/experiment/local/deployment_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/experiment/local/deployment_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/experiment/local/flag_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type flagConfigApi interface {
GetFlagConfigs() (map[string]*evaluation.Flag, error)
getFlagConfigs() (map[string]*evaluation.Flag, error)
}

type flagConfigApiV2 struct {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/experiment/local/flag_config_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type inMemoryFlagConfigStorage struct {
flagConfigsLock sync.Mutex
}

func NewInMemoryFlagConfigStorage() *inMemoryFlagConfigStorage {
func newInMemoryFlagConfigStorage() *inMemoryFlagConfigStorage {
return &inMemoryFlagConfigStorage{
flagConfigs: make(map[string]*evaluation.Flag),
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/experiment/local/flag_config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/experiment/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 {
Expand Down

0 comments on commit 1df8194

Please sign in to comment.