Skip to content

Commit

Permalink
fix: code optimization (#1557)
Browse files Browse the repository at this point in the history
* fix: code optimization

* fix: golangci-lint
  • Loading branch information
testwill authored Jul 27, 2023
1 parent c5102bd commit cb9b2bf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions internal/encoding/dotenv/map_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func flattenAndMergeMap(shadow map[string]interface{}, m map[string]interface{},
}
for k, val := range m {
fullKey := prefix + k
switch val.(type) {
switch val := val.(type) {
case map[string]interface{}:
m2 = val.(map[string]interface{})
m2 = val
case map[interface{}]interface{}:
m2 = cast.ToStringMap(val)
default:
Expand Down
4 changes: 2 additions & 2 deletions internal/encoding/ini/map_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func flattenAndMergeMap(shadow map[string]interface{}, m map[string]interface{},
}
for k, val := range m {
fullKey := prefix + k
switch val.(type) {
switch val := val.(type) {
case map[string]interface{}:
m2 = val.(map[string]interface{})
m2 = val
case map[interface{}]interface{}:
m2 = cast.ToStringMap(val)
default:
Expand Down
4 changes: 2 additions & 2 deletions internal/encoding/javaproperties/map_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func flattenAndMergeMap(shadow map[string]interface{}, m map[string]interface{},
}
for k, val := range m {
fullKey := prefix + k
switch val.(type) {
switch val := val.(type) {
case map[string]interface{}:
m2 = val.(map[string]interface{})
m2 = val
case map[interface{}]interface{}:
m2 = cast.ToStringMap(val)
default:
Expand Down
4 changes: 2 additions & 2 deletions overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ func deepCheckValue(assert *assert.Assertions, v *Viper, l layer, keys []string,
}

// deep scan of the map to get the final value
switch val.(type) {
switch val := val.(type) {
case map[interface{}]interface{}:
m = cast.ToStringMap(val)
case map[string]interface{}:
m = val.(map[string]interface{})
m = val
default:
assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms))
return
Expand Down
6 changes: 3 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ func copyAndInsensitiviseMap(m map[string]interface{}) map[string]interface{} {
}

func insensitiviseVal(val interface{}) interface{} {
switch val.(type) {
switch v := val.(type) {
case map[interface{}]interface{}:
// nested map: cast and recursively insensitivise
val = cast.ToStringMap(val)
insensitiviseMap(val.(map[string]interface{}))
case map[string]interface{}:
// nested map: recursively insensitivise
insensitiviseMap(val.(map[string]interface{}))
insensitiviseMap(v)
case []interface{}:
// nested array: recursively insensitivise
insensitiveArray(val.([]interface{}))
insensitiveArray(v)
}
return val
}
Expand Down
8 changes: 4 additions & 4 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,13 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac
}

// Nested case
switch next.(type) {
switch next := next.(type) {
case map[interface{}]interface{}:
return v.searchMap(cast.ToStringMap(next), path[1:])
case map[string]interface{}:
// Type assertion is safe here since it is only reached
// if the type of `next` is the same as the type being asserted
return v.searchMap(next.(map[string]interface{}), path[1:])
return v.searchMap(next, path[1:])
default:
// got a value but nested key expected, return "nil" for not found
return nil
Expand Down Expand Up @@ -2057,9 +2057,9 @@ func (v *Viper) flattenAndMergeMap(shadow map[string]bool, m map[string]interfac
}
for k, val := range m {
fullKey := prefix + k
switch val.(type) {
switch val := val.(type) {
case map[string]interface{}:
m2 = val.(map[string]interface{})
m2 = val
case map[interface{}]interface{}:
m2 = cast.ToStringMap(val)
default:
Expand Down

0 comments on commit cb9b2bf

Please sign in to comment.