mirror of
https://gitee.com/johng/gf
synced 2026-07-07 06:15:15 +08:00
@ -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 {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user