* version updates

* fix issue #2172
This commit is contained in:
John Guo
2022-10-08 11:46:38 +08:00
committed by GitHub
parent 127e8af6a6
commit f1455ad37a
6 changed files with 57 additions and 4 deletions

View File

@ -40,7 +40,7 @@ const (
// Json is the customized JSON struct.
type Json struct {
mu *rwmutex.RWMutex
mu rwmutex.RWMutex
p *interface{} // Pointer for hierarchical data access, it's the root of data in default.
c byte // Char separator('.' in default).
vc bool // Violence Check(false in default), which is used to access data when the hierarchical data key contains separator char.
@ -358,6 +358,9 @@ func (j *Json) setPointerWithValue(pointer *interface{}, key string, value inter
// getPointerByPattern returns a pointer to the value by specified `pattern`.
func (j *Json) getPointerByPattern(pattern string) *interface{} {
if j.p == nil {
return nil
}
if j.vc {
return j.getPointerByPatternWithViolenceCheck(pattern)
} else {

View File

@ -22,6 +22,9 @@ func (j *Json) Interface() interface{} {
}
j.mu.RLock()
defer j.mu.RUnlock()
if j.p == nil {
return nil
}
return *(j.p)
}

View File

@ -95,7 +95,7 @@ func NewWithOptions(data interface{}, options Options) *Json {
vc: false,
}
}
j.mu = rwmutex.New(options.Safe)
j.mu = rwmutex.Create(options.Safe)
return j
}

View File

@ -37,10 +37,16 @@ func (j *Json) UnmarshalValue(value interface{}) error {
// MapStrAny implements interface function MapStrAny().
func (j *Json) MapStrAny() map[string]interface{} {
if j == nil {
return nil
}
return j.Map()
}
// Interfaces implements interface function Interfaces().
func (j *Json) Interfaces() []interface{} {
if j == nil {
return nil
}
return j.Array()
}