From 5f9ac81aab53a2c1c5af39be36c1ca9e25870f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=98=ED=9B=8C?= Date: Tue, 7 Apr 2020 02:01:12 +0900 Subject: [PATCH] Update distribute-readme.go --- distribute-readme.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/distribute-readme.go b/distribute-readme.go index 1a6e8ee..ffc1d97 100644 --- a/distribute-readme.go +++ b/distribute-readme.go @@ -11,6 +11,21 @@ import ( "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() { typeFile, err := os.Open("type.lst") // if we os.Open returns an error then handle it @@ -52,7 +67,12 @@ func main() { _ = d tool := make(map[string]interface{}) 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 := "" for k, vv := range m {