github.com/enbility/spine-go@v0.7.0/util/helper.go (about)

     1  package util
     2  
     3  import (
     4  	"encoding/json"
     5  	"reflect"
     6  )
     7  
     8  // quick way to a struct into another
     9  func DeepCopy[A any](source, dest A) {
    10  	byt, _ := json.Marshal(source)
    11  	_ = json.Unmarshal(byt, dest)
    12  }
    13  
    14  // checck if a value is nil for any type
    15  func IsNil(data any) bool {
    16  	if data == nil {
    17  		return true
    18  	}
    19  	switch reflect.TypeOf(data).Kind() {
    20  	case reflect.Ptr,
    21  		reflect.Map,
    22  		reflect.Array,
    23  		reflect.Chan,
    24  		reflect.Slice:
    25  		return reflect.ValueOf(data).IsNil()
    26  	}
    27  	return false
    28  }