Use github.com/pkg/errors
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
@@ -18,24 +18,25 @@ package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// DeepCopy makes a deep copy from src into dst.
|
||||
func DeepCopy(dst interface{}, src interface{}) error {
|
||||
if dst == nil {
|
||||
return fmt.Errorf("dst cannot be nil")
|
||||
return errors.New("dst cannot be nil")
|
||||
}
|
||||
if src == nil {
|
||||
return fmt.Errorf("src cannot be nil")
|
||||
return errors.New("src cannot be nil")
|
||||
}
|
||||
bytes, err := json.Marshal(src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to marshal src: %s", err)
|
||||
return errors.Wrap(err, "unable to marshal src")
|
||||
}
|
||||
err = json.Unmarshal(bytes, dst)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to unmarshal into dst: %s", err)
|
||||
return errors.Wrap(err, "unable to unmarshal into dst")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user