Mike Schwörer
758e5a67b5
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m30s
20 lines
274 B
Go
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
|
|
}
|