1Panel/backend/utils/copier/copier.go

19 lines
326 B
Go
Raw Normal View History

2022-08-16 23:30:23 +08:00
package copier
import (
"encoding/json"
"github.com/pkg/errors"
)
func Copy(to, from interface{}) error {
b, err := json.Marshal(from)
if err != nil {
return errors.Wrap(err, "marshal from data err")
}
if err = json.Unmarshal(b, to); err != nil {
return errors.Wrap(err, "unmarshal to data err")
}
return nil
}