Bump github.com/gookit/config/v2 from 2.1.8 to 2.2.2
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.1.8 to 2.2.2. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.1.8...v2.2.2) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
Ralf Haferkamp
parent
03045c5ccc
commit
5ebc596352
+53
-12
@@ -3,12 +3,15 @@ package maputil
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gookit/goutil/arrutil"
|
||||
"github.com/gookit/goutil/mathutil"
|
||||
"github.com/gookit/goutil/strutil"
|
||||
)
|
||||
|
||||
// Data an map data type
|
||||
type Data map[string]any
|
||||
|
||||
// Map alias of Data
|
||||
type Map = Data
|
||||
|
||||
// Has value on the data map
|
||||
@@ -123,6 +126,14 @@ func (d Data) Int64(key string) int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Uint value get
|
||||
func (d Data) Uint(key string) uint64 {
|
||||
if val, ok := d.GetByPath(key); ok {
|
||||
return mathutil.QuietUint(val)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Str value get by key
|
||||
func (d Data) Str(key string) string {
|
||||
if val, ok := d.GetByPath(key); ok {
|
||||
@@ -137,14 +148,15 @@ func (d Data) Bool(key string) bool {
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if bl, ok := val.(bool); ok {
|
||||
return bl
|
||||
}
|
||||
|
||||
if str, ok := val.(string); ok {
|
||||
return strutil.QuietBool(str)
|
||||
switch tv := val.(type) {
|
||||
case string:
|
||||
return strutil.QuietBool(tv)
|
||||
case bool:
|
||||
return tv
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Strings get []string value
|
||||
@@ -154,10 +166,16 @@ func (d Data) Strings(key string) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ss, ok := val.([]string); ok {
|
||||
return ss
|
||||
switch typVal := val.(type) {
|
||||
case string:
|
||||
return []string{typVal}
|
||||
case []string:
|
||||
return typVal
|
||||
case []any:
|
||||
return arrutil.SliceToStrings(typVal)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StrSplit get strings by split key value
|
||||
@@ -176,6 +194,11 @@ func (d Data) StringsByStr(key string) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// StrMap get map[string]string value
|
||||
func (d Data) StrMap(key string) map[string]string {
|
||||
return d.StringMap(key)
|
||||
}
|
||||
|
||||
// StringMap get map[string]string value
|
||||
func (d Data) StringMap(key string) map[string]string {
|
||||
val, ok := d.GetByPath(key)
|
||||
@@ -183,10 +206,14 @@ func (d Data) StringMap(key string) map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
||||
if smp, ok := val.(map[string]string); ok {
|
||||
return smp
|
||||
switch tv := val.(type) {
|
||||
case map[string]string:
|
||||
return tv
|
||||
case map[string]any:
|
||||
return ToStringMap(tv)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sub get sub value as new Data
|
||||
@@ -217,3 +244,17 @@ func (d Data) ToStringMap() map[string]string {
|
||||
func (d Data) String() string {
|
||||
return ToString(d)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user