Bump github.com/gookit/config/v2 from 2.2.2 to 2.2.3
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.2 to 2.2.3. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.2...v2.2.3) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
Ralf Haferkamp
parent
69bd2c24a7
commit
0aafeccb93
+31
-54
@@ -10,76 +10,47 @@ import (
|
||||
)
|
||||
|
||||
// LiteData simple map[string]any struct. no lock
|
||||
type LiteData struct {
|
||||
data map[string]any
|
||||
}
|
||||
type LiteData = Data
|
||||
|
||||
// Data get all
|
||||
func (d *LiteData) Data() map[string]any {
|
||||
return d.data
|
||||
}
|
||||
|
||||
// SetData set all data
|
||||
func (d *LiteData) SetData(data map[string]any) {
|
||||
d.data = data
|
||||
}
|
||||
|
||||
// Value get from data
|
||||
func (d *LiteData) Value(key string) any {
|
||||
return d.data[key]
|
||||
}
|
||||
|
||||
// GetVal get from data
|
||||
func (d *LiteData) GetVal(key string) any {
|
||||
return d.data[key]
|
||||
}
|
||||
|
||||
// StrValue get from data
|
||||
func (d *LiteData) StrValue(key string) string {
|
||||
return strutil.QuietString(d.data[key])
|
||||
}
|
||||
|
||||
// IntVal get from data
|
||||
func (d *LiteData) IntVal(key string) int {
|
||||
return mathutil.QuietInt(d.data[key])
|
||||
}
|
||||
|
||||
// SetValue to data
|
||||
func (d *LiteData) SetValue(key string, val any) {
|
||||
if d.data == nil {
|
||||
d.data = make(map[string]any)
|
||||
// NewLiteData create, not lock
|
||||
func NewLiteData(data map[string]any) *Data {
|
||||
if data == nil {
|
||||
data = make(map[string]any)
|
||||
}
|
||||
d.data[key] = val
|
||||
}
|
||||
|
||||
// ResetData all data
|
||||
func (d *LiteData) ResetData() {
|
||||
d.data = nil
|
||||
return &LiteData{
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* data struct and allow enable lock
|
||||
*************************************************************/
|
||||
|
||||
// Data struct, allow enable lock TODO
|
||||
// Data struct, allow enable lock
|
||||
type Data struct {
|
||||
sync.RWMutex
|
||||
enableLock bool
|
||||
// data store
|
||||
lock bool
|
||||
data map[string]any
|
||||
}
|
||||
|
||||
// NewData create
|
||||
// NewData create new data instance
|
||||
func NewData() *Data {
|
||||
return &Data{
|
||||
lock: true,
|
||||
data: make(map[string]any),
|
||||
}
|
||||
}
|
||||
|
||||
// WithLock for operate data
|
||||
func (d *Data) WithLock() *Data {
|
||||
d.lock = true
|
||||
return d
|
||||
}
|
||||
|
||||
// EnableLock for operate data
|
||||
func (d *Data) EnableLock() *Data {
|
||||
d.enableLock = true
|
||||
return d
|
||||
return d.WithLock()
|
||||
}
|
||||
|
||||
// Data get all
|
||||
@@ -89,7 +60,7 @@ func (d *Data) Data() map[string]any {
|
||||
|
||||
// SetData set all data
|
||||
func (d *Data) SetData(data map[string]any) {
|
||||
if !d.enableLock {
|
||||
if !d.lock {
|
||||
d.data = data
|
||||
return
|
||||
}
|
||||
@@ -109,6 +80,11 @@ func (d *Data) ResetData() {
|
||||
d.data = make(map[string]any)
|
||||
}
|
||||
|
||||
// Merge load new data
|
||||
func (d *Data) Merge(mp map[string]any) {
|
||||
d.data = maputil.SimpleMerge(d.data, mp)
|
||||
}
|
||||
|
||||
// Set value to data
|
||||
func (d *Data) Set(key string, val any) {
|
||||
d.SetValue(key, val)
|
||||
@@ -116,7 +92,7 @@ func (d *Data) Set(key string, val any) {
|
||||
|
||||
// SetValue to data
|
||||
func (d *Data) SetValue(key string, val any) {
|
||||
if d.enableLock {
|
||||
if d.lock {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
}
|
||||
@@ -126,12 +102,12 @@ func (d *Data) SetValue(key string, val any) {
|
||||
|
||||
// Value get from data
|
||||
func (d *Data) Value(key string) (val any, ok bool) {
|
||||
if d.enableLock {
|
||||
if d.lock {
|
||||
d.RLock()
|
||||
defer d.RUnlock()
|
||||
}
|
||||
|
||||
val, ok = d.data[key]
|
||||
val, ok = maputil.GetByPath(key, d.data)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -142,12 +118,13 @@ func (d *Data) Get(key string) any {
|
||||
|
||||
// GetVal get from data
|
||||
func (d *Data) GetVal(key string) any {
|
||||
if d.enableLock {
|
||||
if d.lock {
|
||||
d.RLock()
|
||||
defer d.RUnlock()
|
||||
}
|
||||
|
||||
return d.data[key]
|
||||
val, _ := maputil.GetByPath(key, d.data)
|
||||
return val
|
||||
}
|
||||
|
||||
// StrVal get from data
|
||||
|
||||
Reference in New Issue
Block a user