mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-29 23:10:35 +00:00
20 lines
341 B
Go
20 lines
341 B
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jinzhu/copier"
|
|
)
|
|
|
|
func DeepCopy[T any](src *T) (*T, error) {
|
|
if src == nil {
|
|
return nil, fmt.Errorf("copy source cannot be nil")
|
|
}
|
|
var dst T
|
|
err := copier.CopyWithOption(&dst, src, copier.Option{DeepCopy: true, IgnoreEmpty: true})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &dst, nil
|
|
}
|