package util import ( "errors" "time" "micro-document/pkg/utils/stime" "github.com/jinzhu/copier" ) var CopierProtoOptions = copier.Option{ IgnoreEmpty: true, DeepCopy: true, Converters: []copier.TypeConverter{ { SrcType: time.Time{}, DstType: copier.String, Fn: func(src interface{}) (interface{}, error) { s, ok := src.(time.Time) if !ok { return nil, errors.New("src type :time.Time not matching") } return s.Format(stime.Format_Normal_YMDhms), nil }, }, { SrcType: copier.String, DstType: time.Time{}, Fn: func(src interface{}) (interface{}, error) { s, ok := src.(string) if !ok { return nil, errors.New("src type :time.Time not matching") } tt, err := stime.StringToTimeWithFormat(s, stime.Format_Normal_YMDhms) return *tt, err }, }, }, }