diff --git a/CHANGELOG.md b/CHANGELOG.md index db724e0..989cb7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # go-utils + +## [v1.3.0] - 2020-03-06 +### New Features +- add lower map key + + ## [v1.2.0] - 2020-02-04 ### New Features @@ -21,7 +27,8 @@ - init go-utils -[Unreleased]: https://github.com/kumparan/kumnats/compare/v1.2.0...HEAD +[Unreleased]: https://github.com/kumparan/kumnats/compare/v1.3.0...HEAD +[v1.3.0]: https://github.com/kumparan/kumnats/compare/v1.2.0...v1.3.0 [v1.2.0]: https://github.com/kumparan/kumnats/compare/v1.1.1...v1.2.0 [v1.1.1]: https://github.com/kumparan/kumnats/compare/v1.1.0...v1.1.1 [v1.1.0]: https://github.com/kumparan/kumnats/compare/v1.0.0...v1.1.0 diff --git a/map.go b/map.go new file mode 100644 index 0000000..1c53a14 --- /dev/null +++ b/map.go @@ -0,0 +1,11 @@ +package utils + +import "strings" + +func LowerMapStringKey(v map[string]interface{}) map[string]interface{} { + lv := make(map[string]interface{}, len(v)) + for mk, mv := range v { + lv[strings.ToLower(mk)] = mv + } + return lv +} diff --git a/map_test.go b/map_test.go new file mode 100644 index 0000000..20e4481 --- /dev/null +++ b/map_test.go @@ -0,0 +1,15 @@ +package utils + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_LowerMapStringKey(t *testing.T) { + value := map[string]interface{}{ + "storyID" : "testing", + } + res := LowerMapStringKey(value) + assert.Equal(t, res["storyid"].(string), "testing") +}