Skip to content

Commit cb9b2bf

Browse files
authored
fix: code optimization (#1557)
* fix: code optimization * fix: golangci-lint
1 parent c5102bd commit cb9b2bf

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

internal/encoding/dotenv/map_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func flattenAndMergeMap(shadow map[string]interface{}, m map[string]interface{},
2424
}
2525
for k, val := range m {
2626
fullKey := prefix + k
27-
switch val.(type) {
27+
switch val := val.(type) {
2828
case map[string]interface{}:
29-
m2 = val.(map[string]interface{})
29+
m2 = val
3030
case map[interface{}]interface{}:
3131
m2 = cast.ToStringMap(val)
3232
default:

internal/encoding/ini/map_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func flattenAndMergeMap(shadow map[string]interface{}, m map[string]interface{},
5757
}
5858
for k, val := range m {
5959
fullKey := prefix + k
60-
switch val.(type) {
60+
switch val := val.(type) {
6161
case map[string]interface{}:
62-
m2 = val.(map[string]interface{})
62+
m2 = val
6363
case map[interface{}]interface{}:
6464
m2 = cast.ToStringMap(val)
6565
default:

internal/encoding/javaproperties/map_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func flattenAndMergeMap(shadow map[string]interface{}, m map[string]interface{},
5757
}
5858
for k, val := range m {
5959
fullKey := prefix + k
60-
switch val.(type) {
60+
switch val := val.(type) {
6161
case map[string]interface{}:
62-
m2 = val.(map[string]interface{})
62+
m2 = val
6363
case map[interface{}]interface{}:
6464
m2 = cast.ToStringMap(val)
6565
default:

overrides_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ func deepCheckValue(assert *assert.Assertions, v *Viper, l layer, keys []string,
156156
}
157157

158158
// deep scan of the map to get the final value
159-
switch val.(type) {
159+
switch val := val.(type) {
160160
case map[interface{}]interface{}:
161161
m = cast.ToStringMap(val)
162162
case map[string]interface{}:
163-
m = val.(map[string]interface{})
163+
m = val
164164
default:
165165
assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms))
166166
return

util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ func copyAndInsensitiviseMap(m map[string]interface{}) map[string]interface{} {
7070
}
7171

7272
func insensitiviseVal(val interface{}) interface{} {
73-
switch val.(type) {
73+
switch v := val.(type) {
7474
case map[interface{}]interface{}:
7575
// nested map: cast and recursively insensitivise
7676
val = cast.ToStringMap(val)
7777
insensitiviseMap(val.(map[string]interface{}))
7878
case map[string]interface{}:
7979
// nested map: recursively insensitivise
80-
insensitiviseMap(val.(map[string]interface{}))
80+
insensitiviseMap(v)
8181
case []interface{}:
8282
// nested array: recursively insensitivise
83-
insensitiveArray(val.([]interface{}))
83+
insensitiveArray(v)
8484
}
8585
return val
8686
}

viper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,13 +672,13 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac
672672
}
673673

674674
// Nested case
675-
switch next.(type) {
675+
switch next := next.(type) {
676676
case map[interface{}]interface{}:
677677
return v.searchMap(cast.ToStringMap(next), path[1:])
678678
case map[string]interface{}:
679679
// Type assertion is safe here since it is only reached
680680
// if the type of `next` is the same as the type being asserted
681-
return v.searchMap(next.(map[string]interface{}), path[1:])
681+
return v.searchMap(next, path[1:])
682682
default:
683683
// got a value but nested key expected, return "nil" for not found
684684
return nil
@@ -2057,9 +2057,9 @@ func (v *Viper) flattenAndMergeMap(shadow map[string]bool, m map[string]interfac
20572057
}
20582058
for k, val := range m {
20592059
fullKey := prefix + k
2060-
switch val.(type) {
2060+
switch val := val.(type) {
20612061
case map[string]interface{}:
2062-
m2 = val.(map[string]interface{})
2062+
m2 = val
20632063
case map[interface{}]interface{}:
20642064
m2 = cast.ToStringMap(val)
20652065
default:

0 commit comments

Comments
 (0)