Skip to content

Commit

Permalink
up: update some method for map.Data, add test on go1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Aug 17, 2022
1 parent fb556b3 commit 2ad3436
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
go_version: [1.15, 1.16, 1.17, 1.18]
go_version: [1.16, 1.17, 1.18, 1.19]

steps:
- name: Check out code
Expand Down
24 changes: 12 additions & 12 deletions maputil/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Map = Data

// Has value on the data map
func (d Data) Has(key string) bool {
_, ok := d[key]
_, ok := d.GetByPath(key)
return ok
}

Expand All @@ -24,7 +24,7 @@ func (d Data) IsEmtpy() bool {

// Value get from the data map
func (d Data) Value(key string) (interface{}, bool) {
val, ok := d[key]
val, ok := d.GetByPath(key)
return val, ok
}

Expand Down Expand Up @@ -101,31 +101,31 @@ func (d Data) SetByKeys(keys []string, value any) error {

// Default get value from the data map with default value
func (d Data) Default(key string, def any) interface{} {
if val, ok := d[key]; ok {
if val, ok := d.GetByPath(key); ok {
return val
}
return def
}

// Int value get
func (d Data) Int(key string) int {
if val, ok := d[key]; ok {
if val, ok := d.GetByPath(key); ok {
return mathutil.QuietInt(val)
}
return 0
}

// Int64 value get
func (d Data) Int64(key string) int64 {
if val, ok := d[key]; ok {
if val, ok := d.GetByPath(key); ok {
return mathutil.QuietInt64(val)
}
return 0
}

// Str value get by key
func (d Data) Str(key string) string {
if val, ok := d[key]; ok {
if val, ok := d.GetByPath(key); ok {
return strutil.QuietString(val)
}
return ""
Expand All @@ -149,7 +149,7 @@ func (d Data) Bool(key string) bool {

// Strings get []string value
func (d Data) Strings(key string) []string {
val, ok := d[key]
val, ok := d.GetByPath(key)
if !ok {
return nil
}
Expand All @@ -162,23 +162,23 @@ func (d Data) Strings(key string) []string {

// StrSplit get strings by split key value
func (d Data) StrSplit(key, sep string) []string {
if val, ok := d[key]; ok {
if val, ok := d.GetByPath(key); ok {
return strings.Split(strutil.QuietString(val), sep)
}
return nil
}

// StringsByStr value get by key
func (d Data) StringsByStr(key string) []string {
if val, ok := d[key]; ok {
if val, ok := d.GetByPath(key); ok {
return strings.Split(strutil.QuietString(val), ",")
}
return nil
}

// StringMap get map[string]string value
func (d Data) StringMap(key string) map[string]string {
val, ok := d[key]
val, ok := d.GetByPath(key)
if !ok {
return nil
}
Expand All @@ -191,8 +191,8 @@ func (d Data) StringMap(key string) map[string]string {

// Sub get sub value as new Data
func (d Data) Sub(key string) Data {
if val, ok := d[key]; ok {
if sub, ok := val.(map[string]interface{}); ok {
if val, ok := d.GetByPath(key); ok {
if sub, ok := val.(map[string]any); ok {
return sub
}
}
Expand Down

0 comments on commit 2ad3436

Please sign in to comment.