Skip to content

Commit

Permalink
Merge pull request #4 from kumparan/feature/addlowermap
Browse files Browse the repository at this point in the history
Feature: addlowermap
  • Loading branch information
nuzirwan authored Mar 6, 2020
2 parents 300aba7 + 7eef437 commit 31425eb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# go-utils

<a name="v1.3.0"></a>
## [v1.3.0] - 2020-03-06
### New Features
- add lower map key


<a name="v1.2.0"></a>
## [v1.2.0] - 2020-02-04
### New Features
Expand All @@ -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
11 changes: 11 additions & 0 deletions map.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions map_test.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 31425eb

Please sign in to comment.