Skip to content

Commit

Permalink
👔 up(maputil): update some method logic and add more method for Map
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Mar 18, 2023
1 parent 78243ff commit e7c80d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion maputil/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func KeyToLower(src map[string]string) map[string]string {
func ToStringMap(src map[string]any) map[string]string {
strMp := make(map[string]string, len(src))
for k, v := range src {
strMp[k] = strutil.MustString(v)
strMp[k] = strutil.SafeString(v)
}
return strMp
}
Expand Down
9 changes: 8 additions & 1 deletion maputil/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,16 @@ func (d Data) String() string {
return ToString(d)
}

// Load data to current data map
// Load other data to current data map
func (d Data) Load(sub map[string]any) {
for name, val := range sub {
d[name] = val
}
}

// LoadSMap to data
func (d Data) LoadSMap(smp map[string]string) {
for name, val := range smp {
d[name] = val
}
}
2 changes: 2 additions & 0 deletions maputil/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func TestData_SetByKeys(t *testing.T) {
assert.Nil(t, mp.Get("k3"))
assert.Nil(t, mp.Get("k5.b"))

assert.NoErr(t, mp.SetByKeys([]string{}, "v3"))

err := mp.SetByKeys([]string{"k3"}, "v3")
assert.NoErr(t, err)
assert.Eq(t, "v3", mp.Str("k3"))
Expand Down

0 comments on commit e7c80d4

Please sign in to comment.