Update distribute-readme.go

This commit is contained in:
하훌 2020-04-07 02:01:12 +09:00 committed by GitHub
parent 530b151d5a
commit 5f9ac81aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,21 @@ import (
"strings" "strings"
) )
type mmm = map[string]interface{}
func mergeKeys(left, right mmm) mmm {
for key, rightVal := range right {
if leftVal, present := left[key]; present {
//then we don't want to replace it - recurse
left[key] = mergeKeys(leftVal.(mmm), rightVal.(mmm))
} else {
// key not in left so we can just shove it in
left[key] = rightVal
}
}
return left
}
func main() { func main() {
typeFile, err := os.Open("type.lst") typeFile, err := os.Open("type.lst")
// if we os.Open returns an error then handle it // if we os.Open returns an error then handle it
@ -52,7 +67,12 @@ func main() {
_ = d _ = d
tool := make(map[string]interface{}) tool := make(map[string]interface{})
tool[k] = d tool[k] = d
m[t] = tool fmt.Println(reflect.TypeOf(m[t]).String())
if reflect.TypeOf(m[t]).String() == "string" {
m[t] = tool
} else {
m[t] = mergeKeys(tool, m[t].(map[string]interface{}))
}
} }
readme := "" readme := ""
for k, vv := range m { for k, vv := range m {