Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit a76681b

Browse files
committed
use spf13/cast for casting interface{} as string map
1 parent c9884eb commit a76681b

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

main.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/Masterminds/vcs"
7+
"github.com/spf13/cast"
78
"github.com/spf13/viper"
89
)
910

@@ -45,9 +46,9 @@ func ExpandConfig(dir string, entries map[string]interface{}, repos *[]LegacyRep
4546
remotes: nil,
4647
})
4748
case map[interface{}]interface{}:
48-
r := castToMapStringInterface(repo.(map[interface{}]interface{}))
49+
r := cast.ToStringMap(repo.(map[interface{}]interface{}))
4950
if r["remotes"] != nil {
50-
for remote_name, remote := range castToMapStringString(r["remotes"].(map[interface{}]interface{})) {
51+
for remote_name, remote := range cast.ToStringMapString(r["remotes"].(map[interface{}]interface{})) {
5152
*repos = append(*repos, LegacyRepoConf{
5253
name: name,
5354
path: dir,
@@ -71,19 +72,3 @@ func ExpandConfig(dir string, entries map[string]interface{}, repos *[]LegacyRep
7172
}
7273
}
7374
}
74-
75-
func castToMapStringInterface(src map[interface{}]interface{}) map[string]interface{} {
76-
tgt := map[string]interface{}{}
77-
for k, v := range src {
78-
tgt[fmt.Sprintf("%v", k)] = v
79-
}
80-
return tgt
81-
}
82-
83-
func castToMapStringString(src map[interface{}]interface{}) map[string]string {
84-
tgt := make(map[string]string)
85-
for k, v := range src {
86-
tgt[fmt.Sprintf("%v", k)] = v.(string)
87-
}
88-
return tgt
89-
}

0 commit comments

Comments
 (0)