Skip to content

Commit

Permalink
🚀 chore: Adjust the code
Browse files Browse the repository at this point in the history
  • Loading branch information
sohaha committed Aug 3, 2024
1 parent 8d8ba3d commit 8f9b429
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
24 changes: 15 additions & 9 deletions zjson/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -1983,15 +1983,21 @@ func assign(jsval *Res, val reflect.Value, fmap *fieldMaps) {
key := t.Key()
s := key.Kind() == reflect.String
if s {
v := reflect.MakeMap(t)
jsval.ForEach(func(key, value *Res) bool {
newval := reflect.New(t.Elem())
elem := newval.Elem()
assign(value, elem, fmap)
v.SetMapIndex(zreflect.ValueOf(key.Value()), elem)
return true
})
val.Set(v)
kind := t.Elem().Kind()
switch kind {
case reflect.Interface:
val.Set(zreflect.ValueOf(jsval.Value()))
case reflect.Struct, reflect.Ptr:
v := reflect.MakeMap(t)
jsval.ForEach(func(key, value *Res) bool {
newval := reflect.New(t.Elem())
elem := newval.Elem()
assign(value, elem, fmap)
v.SetMapIndex(zreflect.ValueOf(key.Value()), elem)
return true
})
val.Set(v)
}
}
case reflect.Interface:
val.Set(zreflect.ValueOf(jsval.Value()))
Expand Down
1 change: 0 additions & 1 deletion zstring/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (iw *IDWorker) timeGen() int64 {

func (iw *IDWorker) timeReGen(last int64) int64 {
ts := iw.timeGen()
println(ts, last, last-ts)
for {
if ts < last {
ts = iw.timeGen()
Expand Down
2 changes: 2 additions & 0 deletions ztype/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func ToSlice(value interface{}, noConv ...bool) (s SliceType) {
return
}
s = SliceType{New(val)}
case Type:
return ToSlice(val.Value())
default:
var nval []interface{}
vof := zreflect.ValueOf(&nval)
Expand Down

0 comments on commit 8f9b429

Please sign in to comment.