Skip to content

Commit 00c60fb

Browse files
committed
added changes to optimize loop
1 parent 4543a64 commit 00c60fb

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

localEvaluation/localEvaluation.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ type AmplitudeConfig struct {
4444
FlagConfigPollerRequestTimeout time.Duration
4545
}
4646

47-
type AmplitudeVariant struct {
48-
Value string `json:"value,omitempty"`
49-
Payload interface{} `json:"payload,omitempty"`
50-
}
51-
5247
func init() {
5348
err := godotenv.Load()
5449
if err != nil {
@@ -123,11 +118,8 @@ func fetch(user UserProperties) (*local.EvaluationResult, error) {
123118
}
124119

125120
func getValue(flagName string, user UserProperties) local.EvaluationVariant {
126-
result, err := fetch(user)
127-
if err != nil {
128-
fmt.Errorf("error in fetch: %s", err.Error())
129-
}
130-
if result != nil {
121+
result, _ := fetch(user)
122+
if *result != nil {
131123
if value, ok := (*result)[flagName]; ok {
132124
return value.Variant
133125
}
@@ -137,15 +129,14 @@ func getValue(flagName string, user UserProperties) local.EvaluationVariant {
137129

138130
func getMapOfValue(user UserProperties) map[string]interface{} {
139131
flags := make(map[string]interface{})
140-
result, err := fetch(user)
141-
if err != nil {
142-
fmt.Errorf("error in fetch: %s", err.Error())
143-
}
144-
for k, v := range *result {
145-
if v.IsDefaultVariant {
146-
continue
132+
result, _ := fetch(user)
133+
if *result != nil {
134+
for k, v := range *result {
135+
if v.IsDefaultVariant {
136+
continue
137+
}
138+
flags[k] = v.Variant.Key
147139
}
148-
flags[k] = v.Variant.Key
149140
}
150141
return flags
151142
}

0 commit comments

Comments
 (0)