goext/langext/object.go
Mike Schwörer 758e5a67b5
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m30s
v0.0.427
2024-04-07 15:10:21 +02:00

20 lines
274 B
Go

package langext
import "encoding/json"
func DeepCopyByJson[T any](v T) (T, error) {
bin, err := json.Marshal(v)
if err != nil {
return *new(T), err
}
var result T
err = json.Unmarshal(bin, &result)
if err != nil {
return *new(T), err
}
return result, nil
}