Skip to content

Commit 8d510c1

Browse files
committed
chore: address review #686 (comment), update comments
1 parent da8aab7 commit 8d510c1

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

remoteconfig/condition_evaluator.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ func (ce *conditionEvaluator) evaluatePercentCondition(percentCondition *percent
148148
}
149149

150150
func computeInstanceMicroPercentile(seed string, randomizationID string) uint32 {
151-
seedPrefix := ""
151+
var sb strings.Builder
152152
if len(seed) > 0 {
153-
seedPrefix = fmt.Sprintf("%s.", seed)
153+
sb.WriteString(seed)
154+
sb.WriteRune('.')
154155
}
155-
stringToHash := fmt.Sprintf("%s%s", seedPrefix, randomizationID)
156+
sb.WriteString(randomizationID)
157+
stringToHash := sb.String()
156158

157159
hash := sha256.New()
158160
hash.Write([]byte(stringToHash))

remoteconfig/remoteconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Package remoteconfig allows clients to use Firebase Remote Config.
15+
// Package remoteconfig provides functions to fetch and evaluate a server-side Remote Config template.
1616
package remoteconfig
1717

1818
import (
@@ -78,7 +78,7 @@ func newRcClient(client *internal.HTTPClient, conf *internal.RemoteConfigClientC
7878
}
7979
}
8080

81-
// GetServerTemplate Initializes a new ServerTemplate instance and fetches the server template.
81+
// GetServerTemplate initializes a new ServerTemplate instance and fetches the server template.
8282
func (c *rcClient) GetServerTemplate(ctx context.Context,
8383
defaultConfig map[string]any) (*ServerTemplate, error) {
8484
template, err := c.InitServerTemplate(defaultConfig, "")

remoteconfig/server_config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (s *ServerConfig) GetInt(key string) int {
7575
// GetFloat returns the float value associated with the given key.
7676
//
7777
// If the parameter value cannot be parsed as a float64, or if the key is not found,
78-
// it returns the default numeric value (0).
78+
// it returns the default float value (0).
7979
func (s *ServerConfig) GetFloat(key string) float64 {
8080
return s.getValue(key).asFloat()
8181
}
@@ -136,12 +136,12 @@ func (v *value) asInt() int {
136136
return num
137137
}
138138

139-
// asFloat returns the value as an integer.
139+
// asFloat returns the value as a float.
140140
func (v *value) asFloat() float64 {
141141
if v.source == Static {
142142
return defaultValueForNumber
143143
}
144-
num, err := strconv.ParseFloat(v.value, 64)
144+
num, err := strconv.ParseFloat(v.value, doublePrecision)
145145

146146
if err != nil {
147147
return defaultValueForNumber

remoteconfig/server_template.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (s *ServerTemplate) Evaluate(context map[string]any) (*ServerConfig, error)
130130
config[key] = value{source: Default, value: inAppDefault}
131131
}
132132

133-
usedConditions := s.cache.Load().getUsedConditions()
133+
usedConditions := s.cache.Load().filterUsedConditions()
134134
ce := conditionEvaluator{
135135
conditions: usedConditions,
136136
evaluationContext: context,
@@ -164,7 +164,8 @@ func (s *ServerTemplate) Evaluate(context map[string]any) (*ServerConfig, error)
164164
return newServerConfig(config), nil
165165
}
166166

167-
func (s *serverTemplateData) getUsedConditions() []namedCondition {
167+
// filterUsedConditions identifies conditions that are referenced by parameters and returns them in order of decreasing priority.
168+
func (s *serverTemplateData) filterUsedConditions() []namedCondition {
168169
usedConditionNames := make(map[string]struct{})
169170
for _, parameter := range s.Parameters {
170171
for name := range parameter.ConditionalValues {

remoteconfig/server_template_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,10 @@ func TestGetUsedConditions(t *testing.T) {
450450

451451
for _, tc := range testCases {
452452
t.Run(tc.name, func(t *testing.T) {
453-
used := tc.data.getUsedConditions()
453+
used := tc.data.filterUsedConditions()
454454

455455
if len(used) != len(tc.expectedConditions) {
456-
t.Fatalf("getUsedConditions() returned %d conditions, want %d", len(used), len(tc.expectedConditions))
456+
t.Fatalf("filterUsedConditions() returned %d conditions, want %d", len(used), len(tc.expectedConditions))
457457
}
458458

459459
for idx, ec := range tc.expectedConditions {

0 commit comments

Comments
 (0)