feat: copier util
This commit is contained in:
43
copierutil/converters.go
Normal file
43
copierutil/converters.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package copierutil
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/tx7do/go-utils/timeutil"
|
||||
"github.com/tx7do/go-utils/trans"
|
||||
)
|
||||
|
||||
var TimeToStringConverter = copier.TypeConverter{
|
||||
SrcType: &time.Time{}, // 源类型
|
||||
DstType: trans.Ptr(""), // 目标类型
|
||||
Fn: func(src interface{}) (interface{}, error) {
|
||||
return timeutil.TimeToTimeString(src.(*time.Time)), nil
|
||||
},
|
||||
}
|
||||
|
||||
var StringToTimeConverter = copier.TypeConverter{
|
||||
SrcType: trans.Ptr(""),
|
||||
DstType: &time.Time{},
|
||||
Fn: func(src interface{}) (interface{}, error) {
|
||||
return timeutil.StringTimeToTime(src.(*string)), nil
|
||||
},
|
||||
}
|
||||
|
||||
var TimeToTimestamppbConverter = copier.TypeConverter{
|
||||
SrcType: &time.Time{},
|
||||
DstType: ×tamppb.Timestamp{},
|
||||
Fn: func(src interface{}) (interface{}, error) {
|
||||
return timeutil.TimeToTimestamppb(src.(*time.Time)), nil
|
||||
},
|
||||
}
|
||||
|
||||
var TimestamppbToTimeConverter = copier.TypeConverter{
|
||||
SrcType: ×tamppb.Timestamp{},
|
||||
DstType: &time.Time{},
|
||||
Fn: func(src interface{}) (interface{}, error) {
|
||||
return timeutil.TimestamppbToTime(src.(*timestamppb.Timestamp)), nil
|
||||
},
|
||||
}
|
||||
14
copierutil/go.mod
Normal file
14
copierutil/go.mod
Normal file
@@ -0,0 +1,14 @@
|
||||
module github.com/tx7do/go-utils/copierutil
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.24.3
|
||||
|
||||
require (
|
||||
github.com/jinzhu/copier v0.4.0
|
||||
github.com/tx7do/go-utils v1.1.22
|
||||
)
|
||||
|
||||
require google.golang.org/protobuf v1.36.6 // indirect
|
||||
|
||||
replace github.com/tx7do/go-utils => ../
|
||||
16
copierutil/go.sum
Normal file
16
copierutil/go.sum
Normal file
@@ -0,0 +1,16 @@
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
|
||||
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
1
tag.bat
1
tag.bat
@@ -3,6 +3,7 @@ git tag v1.1.22
|
||||
git tag bank_card/v1.1.5
|
||||
git tag geoip/v1.1.5
|
||||
git tag translator/v1.1.1
|
||||
git tag copierutil/v0.0.1
|
||||
|
||||
git tag entgo/v1.1.27
|
||||
git tag gorm/v1.1.5
|
||||
|
||||
16
upgrade.bat
16
upgrade.bat
@@ -10,10 +10,22 @@ cd %DIR%/bank_card
|
||||
go get all
|
||||
go mod tidy
|
||||
|
||||
cd %DIR%/geoip
|
||||
go get all
|
||||
go mod tidy
|
||||
|
||||
cd %DIR%/copierutil
|
||||
go get all
|
||||
go mod tidy
|
||||
|
||||
cd %DIR%/translator
|
||||
go get all
|
||||
go mod tidy
|
||||
|
||||
cd %DIR%/entgo
|
||||
go get all
|
||||
go mod tidy
|
||||
|
||||
cd %DIR%/geoip
|
||||
cd %DIR%/gorm
|
||||
go get all
|
||||
go mod tidy
|
||||
go mod tidy
|
||||
Reference in New Issue
Block a user