Skip to content

Commit ef08cb5

Browse files
committed
chore: remove refactor changes
1 parent dcb8107 commit ef08cb5

File tree

5 files changed

+56
-96
lines changed

5 files changed

+56
-96
lines changed

remoteconfig/remoteconfig.go

Lines changed: 1 addition & 1 deletion
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 allows clients to use Firebase Remote Config with Go.
1616
package remoteconfig
1717

1818
import (

remoteconfig/server_config.go

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package remoteconfig
1616

1717
import (
18-
"slices"
1918
"strconv"
2019
"strings"
2120
)
@@ -27,8 +26,8 @@ type ValueSource int
2726
const (
2827
sourceUnspecified ValueSource = iota
2928
Static // Static represents a statically defined value.
30-
Remote // Remote represents a value fetched from a remote source.
31-
Default // Default represents a default value.
29+
Remote // Default represents a default value.
30+
Default // Remote represents a value fetched from a remote source.
3231
)
3332

3433
// Value defines the interface for configuration values.
@@ -39,50 +38,39 @@ type value struct {
3938

4039
// Default Values for config parameters.
4140
const (
42-
defaultValueForBoolean = false
43-
defaultValueForString = ""
44-
defaultValueForNumber = 0
41+
DefaultValueForBoolean = false
42+
DefaultValueForString = ""
43+
DefaultValueForNumber = 0
4544
)
4645

4746
var booleanTruthyValues = []string{"1", "true", "t", "yes", "y", "on"}
4847

4948
// ServerConfig is the implementation of the ServerConfig interface.
5049
type ServerConfig struct {
51-
configValues map[string]value
50+
ConfigValues map[string]value
5251
}
5352

5453
// NewServerConfig creates a new ServerConfig instance.
55-
func newServerConfig(configValues map[string]value) *ServerConfig {
56-
return &ServerConfig{configValues: configValues}
54+
func NewServerConfig(configValues map[string]value) *ServerConfig {
55+
return &ServerConfig{ConfigValues: configValues}
5756
}
5857

5958
// GetBoolean returns the boolean value associated with the given key.
60-
//
61-
// It returns true if the string value is "1", "true", "t", "yes", "y", or "on" (case-insensitive).
62-
// Otherwise, or if the key is not found, it returns the default boolean value (false).
6359
func (s *ServerConfig) GetBoolean(key string) bool {
6460
return s.getValue(key).asBoolean()
6561
}
6662

6763
// GetInt returns the integer value associated with the given key.
68-
//
69-
// If the parameter value cannot be parsed as an integer, or if the key is not found,
70-
// it returns the default numeric value (0).
7164
func (s *ServerConfig) GetInt(key string) int {
7265
return s.getValue(key).asInt()
7366
}
7467

7568
// GetFloat returns the float value associated with the given key.
76-
//
77-
// 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).
7969
func (s *ServerConfig) GetFloat(key string) float64 {
8070
return s.getValue(key).asFloat()
8171
}
8272

8373
// GetString returns the string value associated with the given key.
84-
//
85-
// If the key is not found, it returns the default string value ("").
8674
func (s *ServerConfig) GetString(key string) string {
8775
return s.getValue(key).asString()
8876
}
@@ -94,16 +82,16 @@ func (s *ServerConfig) GetValueSource(key string) ValueSource {
9482

9583
// getValue returns the value associated with the given key.
9684
func (s *ServerConfig) getValue(key string) *value {
97-
if val, ok := s.configValues[key]; ok {
85+
if val, ok := s.ConfigValues[key]; ok {
9886
return &val
9987
}
100-
return newValue(Static, defaultValueForString)
88+
return newValue(Static, "")
10189
}
10290

10391
// newValue creates a new value instance.
10492
func newValue(source ValueSource, customValue string) *value {
10593
if customValue == "" {
106-
customValue = defaultValueForString
94+
customValue = DefaultValueForString
10795
}
10896
return &value{source: source, value: customValue}
10997
}
@@ -116,21 +104,27 @@ func (v *value) asString() string {
116104
// asBoolean returns the value as a boolean.
117105
func (v *value) asBoolean() bool {
118106
if v.source == Static {
119-
return defaultValueForBoolean
107+
return DefaultValueForBoolean
108+
}
109+
110+
for _, truthyValue := range booleanTruthyValues {
111+
if strings.ToLower(v.value) == truthyValue {
112+
return true
113+
}
120114
}
121115

122-
return slices.Contains(booleanTruthyValues, strings.ToLower(v.value))
116+
return false
123117
}
124118

125119
// asInt returns the value as an integer.
126120
func (v *value) asInt() int {
127121
if v.source == Static {
128-
return defaultValueForNumber
122+
return DefaultValueForNumber
129123
}
130124
num, err := strconv.Atoi(v.value)
131125

132126
if err != nil {
133-
return defaultValueForNumber
127+
return DefaultValueForNumber
134128
}
135129

136130
return num
@@ -139,12 +133,12 @@ func (v *value) asInt() int {
139133
// asFloat returns the value as an integer.
140134
func (v *value) asFloat() float64 {
141135
if v.source == Static {
142-
return defaultValueForNumber
136+
return DefaultValueForNumber
143137
}
144138
num, err := strconv.ParseFloat(v.value, 64)
145139

146140
if err != nil {
147-
return defaultValueForNumber
141+
return DefaultValueForNumber
148142
}
149143

150144
return num

remoteconfig/server_template.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ import (
2828

2929
// serverTemplateData stores the internal representation of the server template.
3030
type serverTemplateData struct {
31-
// A list of conditions in descending order by priority.
32-
Conditions []namedCondition `json:"conditions,omitempty"`
33-
34-
// Map of parameter keys to their optional default values and optional conditional values.
3531
Parameters map[string]parameter `json:"parameters,omitempty"`
3632

37-
// Version information for the current Remote Config template.
38-
Version version `json:"version,omitempty"`
33+
Conditions []namedCondition `json:"conditions,omitempty"`
34+
35+
Version struct {
36+
VersionNumber string `json:"versionNumber"`
37+
IsLegacy bool `json:"isLegacy"`
38+
} `json:"version"`
3939

40-
// Current Remote Config template ETag.
41-
ETag string `json:"etag,omitempty"`
40+
ETag string `json:"etag"`
4241
}
4342

4443
// ServerTemplate represents a template with configuration data, cache, and service information.
@@ -58,8 +57,8 @@ func newServerTemplate(rcClient *rcClient, defaultConfig map[string]any) (*Serve
5857
continue
5958
}
6059

61-
if s, ok := value.(string); ok {
62-
stringifiedConfig[key] = s
60+
if stringVal, ok := value.(string); ok {
61+
stringifiedConfig[key] = stringVal
6362
continue
6463
}
6564

@@ -159,5 +158,5 @@ func (s *ServerTemplate) Evaluate(context map[string]any) (*ServerConfig, error)
159158
config[key] = value{source: Remote, value: *parameter.DefaultValue.Value}
160159
}
161160
}
162-
return newServerConfig(config), nil
161+
return NewServerConfig(config), nil
163162
}

remoteconfig/server_template_test.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ func TestServerTemplateToJSONSuccess(t *testing.T) {
100100
},
101101
},
102102
},
103-
Version: version{
103+
Version: struct {
104+
VersionNumber string "json:\"versionNumber\""
105+
IsLegacy bool "json:\"isLegacy\""
106+
}{
104107
VersionNumber: testVersion,
108+
IsLegacy: true,
105109
},
106110
ETag: testEtag,
107111
}
@@ -111,13 +115,12 @@ func TestServerTemplateToJSONSuccess(t *testing.T) {
111115
t.Fatalf("ServerTemplate.ToJSON failed: %v", err)
112116
}
113117

114-
expectedJSON := `{"parameters":{"test_param_one":{"defaultValue":{"value":"test_value_one"}}},"version":{"versionNumber":"test-version"},"etag":"test-etag"}`
118+
expectedJSON := `{"parameters":{"test_param_one":{"defaultValue":{"value":"test_value_one"}}},"version":{"versionNumber":"test-version","isLegacy":true},"etag":"test-etag"}`
115119
if json != expectedJSON {
116120
t.Fatalf("ServerTemplate.ToJSON returned incorrect json: %v want %v", json, expectedJSON)
117121
}
118122
}
119123

120-
// Verifies that Evaluate returns the explicit default value defined in the template (with Remote source) when the template has no conditions.
121124
func TestServerTemplateReturnsDefaultFromRemote(t *testing.T) {
122125
paramVal := valueOne
123126
template := &ServerTemplate{}
@@ -129,7 +132,10 @@ func TestServerTemplateReturnsDefaultFromRemote(t *testing.T) {
129132
},
130133
},
131134
},
132-
Version: version{
135+
Version: struct {
136+
VersionNumber string "json:\"versionNumber\""
137+
IsLegacy bool "json:\"isLegacy\""
138+
}{
133139
VersionNumber: testVersion,
134140
},
135141
ETag: testEtag,
@@ -155,8 +161,6 @@ func TestServerTemplateReturnsDefaultFromRemote(t *testing.T) {
155161
}
156162
}
157163

158-
// Verifies that Evaluate correctly handles the UseInAppDefault flag for a parameter's default value,
159-
// returning the provided in-app default (with Default source) if available, or the static default (with Static source) otherwise.
160164
func TestEvaluateReturnsInAppDefault(t *testing.T) {
161165
booleanTrue := true
162166
td := &serverTemplateData{
@@ -167,7 +171,10 @@ func TestEvaluateReturnsInAppDefault(t *testing.T) {
167171
},
168172
},
169173
},
170-
Version: version{
174+
Version: struct {
175+
VersionNumber string "json:\"versionNumber\""
176+
IsLegacy bool "json:\"isLegacy\""
177+
}{
171178
VersionNumber: testVersion,
172179
},
173180
ETag: testEtag,
@@ -220,7 +227,6 @@ func TestEvaluateReturnsInAppDefault(t *testing.T) {
220227
}
221228
}
222229

223-
// Verifies that Evaluate returns the explicit conditional value (with Remote source) when the associated condition evaluates to true
224230
func TestEvaluate_WithACondition_ReturnsConditionalRemoteValue(t *testing.T) {
225231
vOne := valueOne
226232
vTwo := valueTwo
@@ -260,7 +266,10 @@ func TestEvaluate_WithACondition_ReturnsConditionalRemoteValue(t *testing.T) {
260266
},
261267
},
262268
},
263-
Version: version{
269+
Version: struct {
270+
VersionNumber string "json:\"versionNumber\""
271+
IsLegacy bool "json:\"isLegacy\""
272+
}{
264273
VersionNumber: testVersion,
265274
},
266275
ETag: testEtag,
@@ -286,8 +295,6 @@ func TestEvaluate_WithACondition_ReturnsConditionalRemoteValue(t *testing.T) {
286295
}
287296
}
288297

289-
// Verifies that Evaluate returns the in-app default value (with Default source) when a condition evaluates to true,
290-
// and its corresponding conditional value specifies UseInAppDefault.
291298
func TestEvaluate_WithACondition_ReturnsConditionalInAppDefaultValue(t *testing.T) {
292299
vOne := valueOne
293300
boolTrue := true
@@ -328,7 +335,10 @@ func TestEvaluate_WithACondition_ReturnsConditionalInAppDefaultValue(t *testing.
328335
},
329336
},
330337
},
331-
Version: version{
338+
Version: struct {
339+
VersionNumber string "json:\"versionNumber\""
340+
IsLegacy bool "json:\"isLegacy\""
341+
}{
332342
VersionNumber: testVersion,
333343
},
334344
ETag: testEtag,

remoteconfig/server_template_types.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -111,46 +111,3 @@ type parameterValue struct {
111111
// If true, indicates that the in-app default value is to be used for the parameter
112112
UseInAppDefault *bool `json:"useInAppDefault,omitempty"`
113113
}
114-
115-
// Structure representing a Remote Config template version.
116-
// Output only, except for the version description. Contains metadata about a particular
117-
// version of the Remote Config template. All fields are set at the time the specified Remote Config template is published.
118-
type version struct {
119-
// The version number of a Remote Config template.
120-
VersionNumber string `json:"versionNumber,omitempty"`
121-
122-
// The timestamp of when this version of the Remote Config template was written to the
123-
// Remote Config backend.
124-
UpdateTime string `json:"updateTime,omitempty"`
125-
126-
// The origin of the template update action.
127-
UpdateOrigin string `json:"updateOrigin,omitempty"`
128-
129-
// The type of the template update action.
130-
UpdateType string `json:"updateType,omitempty"`
131-
132-
// Aggregation of all metadata fields about the account that performed the update.
133-
UpdateUser *remoteConfigUser `json:"updateUser,omitempty"`
134-
135-
// The user-provided description of the corresponding Remote Config template.
136-
Description string `json:"description,omitempty"`
137-
138-
// The version number of the Remote Config template that has become the current version
139-
// due to a rollback. Only present if this version is the result of a rollback.
140-
RollbackSource string `json:"rollbackSource,omitempty"`
141-
142-
// Indicates whether this Remote Config template was published before version history was supported.
143-
IsLegacy bool `json:"isLegacy,omitempty"`
144-
}
145-
146-
// Represents a Remote Config user.
147-
type remoteConfigUser struct {
148-
// Email address. Output only.
149-
Email string `json:"email,omitempty"`
150-
151-
// Display name. Output only.
152-
Name string `json:"name,omitempty"`
153-
154-
// Image URL. Output only.
155-
ImageURL string `json:"imageUrl,omitempty"`
156-
}

0 commit comments

Comments
 (0)