-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[config][util] Use MergeStringMap in config #2
- add util function to merge two map[string]interface{} - add ParseSingleDocumentBytes and call it in ParseMultipleDocumentBytes
- Loading branch information
Showing
4 changed files
with
87 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package util | ||
|
||
// MergeStringMap merges the second map to first map, and keep the value of the second map if there is duplicate key | ||
func MergeStringMap(dst map[string]interface{}, extra map[string]interface{}) { | ||
// TODO: rename extra to a more clear name | ||
for k, v := range extra { | ||
dst[k] = v | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
asst "github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMergeStringMap(t *testing.T) { | ||
assert := asst.New(t) | ||
m := make(map[string]interface{}) | ||
m2 := make(map[string]interface{}) | ||
m["a"] = 123 | ||
m2["a"] = 124 | ||
m2["b"] = 125 | ||
MergeStringMap(m, m2) | ||
assert.Equal(124, m["a"]) | ||
assert.Equal(2, len(m)) | ||
} |