// Package util ----------------------------- // @file : copierOptions.go // @author : JJXu // @contact : wavingbear@163.com // @time : 2023/8/18 12:00 // ------------------------------------------- package util import ( "errors" "github.com/fonchain/fonchain-container/pkg/util/stime" "github.com/jinzhu/copier" "time" ) 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 }, }, }, }