1
This commit is contained in:
parent
eb3b6db5d2
commit
efc8d7fa4b
8
common/vo/vo.go
Normal file
8
common/vo/vo.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package vo
|
||||||
|
|
||||||
|
type TransferRequest struct {
|
||||||
|
SourceUserId int
|
||||||
|
TargetAccountNumber string
|
||||||
|
TargetAmount float64
|
||||||
|
TargetCurrency string
|
||||||
|
}
|
59
go.mod
Normal file
59
go.mod
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
module dddexample
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/IBM/sarama v1.41.2
|
||||||
|
github.com/gin-gonic/gin v1.9.1
|
||||||
|
gorm.io/driver/mysql v1.5.1
|
||||||
|
gorm.io/gorm v1.25.1
|
||||||
|
gorm.io/plugin/soft_delete v1.2.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/bytedance/sonic v1.9.1 // indirect
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/eapache/go-resiliency v1.4.0 // indirect
|
||||||
|
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
|
||||||
|
github.com/eapache/queue v1.1.0 // indirect
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0 // indirect
|
||||||
|
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||||
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
|
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||||
|
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||||
|
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
||||||
|
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
|
||||||
|
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
|
||||||
|
github.com/jcmturner/gofork v1.7.6 // indirect
|
||||||
|
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
|
||||||
|
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
|
||||||
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/klauspost/compress v1.16.7 // indirect
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.4 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
||||||
|
github.com/pierrec/lz4/v4 v4.1.18 // indirect
|
||||||
|
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||||
|
golang.org/x/arch v0.3.0 // indirect
|
||||||
|
golang.org/x/crypto v0.13.0 // indirect
|
||||||
|
golang.org/x/net v0.15.0 // indirect
|
||||||
|
golang.org/x/sys v0.12.0 // indirect
|
||||||
|
golang.org/x/text v0.13.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.30.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
182
go.sum
Normal file
182
go.sum
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
github.com/IBM/sarama v1.41.2 h1:ZDBZfGPHAD4uuAtSv4U22fRZBgst0eEwGFzLj0fb85c=
|
||||||
|
github.com/IBM/sarama v1.41.2/go.mod h1:xdpu7sd6OE1uxNdjYTSKUfY8FaKkJES9/+EyjSgiGQk=
|
||||||
|
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
||||||
|
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
|
||||||
|
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
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/eapache/go-resiliency v1.4.0 h1:3OK9bWpPk5q6pbFAaYSEwD9CLUSHG8bnZuqX2yMt3B0=
|
||||||
|
github.com/eapache/go-resiliency v1.4.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
|
||||||
|
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws=
|
||||||
|
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0=
|
||||||
|
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
|
||||||
|
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||||
|
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||||
|
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
|
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
|
||||||
|
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||||
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||||
|
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
|
||||||
|
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||||
|
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||||
|
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||||
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||||
|
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
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/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||||
|
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||||
|
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||||
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||||
|
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||||
|
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
|
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
|
||||||
|
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
|
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
|
||||||
|
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
|
||||||
|
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
|
||||||
|
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
|
||||||
|
github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg=
|
||||||
|
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
|
||||||
|
github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o=
|
||||||
|
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
|
||||||
|
github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8=
|
||||||
|
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
|
||||||
|
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
|
||||||
|
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
|
||||||
|
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||||
|
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||||
|
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
|
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
|
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||||
|
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
|
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
||||||
|
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||||
|
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
||||||
|
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||||
|
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||||
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.3 h1:j7a/xn1U6TKA/PHHxqZuzh64CdtRc7rU9M+AvkOl5bA=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.3/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
|
||||||
|
github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ=
|
||||||
|
github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||||
|
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/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
|
||||||
|
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||||
|
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||||
|
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
|
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||||
|
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||||
|
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
|
||||||
|
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
|
||||||
|
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||||
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||||
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
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.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||||
|
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
|
||||||
|
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
|
||||||
|
gorm.io/driver/sqlite v1.1.3 h1:BYfdVuZB5He/u9dt4qDpZqiqDJ6KhPqs5QUqsr/Eeuc=
|
||||||
|
gorm.io/driver/sqlite v1.1.3/go.mod h1:AKDgRWk8lcSQSw+9kxCJnX/yySj8G3rdwYlU57cB45c=
|
||||||
|
gorm.io/gorm v1.20.1/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||||
|
gorm.io/gorm v1.23.0/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
|
||||||
|
gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
|
||||||
|
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
||||||
|
gorm.io/plugin/soft_delete v1.2.1 h1:qx9D/c4Xu6w5KT8LviX8DgLcB9hkKl6JC9f44Tj7cGU=
|
||||||
|
gorm.io/plugin/soft_delete v1.2.1/go.mod h1:Zv7vQctOJTGOsJ/bWgrN1n3od0GBAZgnLjEx+cApLGk=
|
||||||
|
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
16
main.go
Normal file
16
main.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package dddexample
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/normal/controller"
|
||||||
|
"dddexample/pkg/interfaces"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
//使用默认gin路由
|
||||||
|
r := gin.Default()
|
||||||
|
|
||||||
|
r.POST("test1", controller.Transfer) //详情,微信购买
|
||||||
|
r.POST("test2", interfaces.Transfer) //详情,微信购买
|
||||||
|
|
||||||
|
}
|
67
normal/common/common.go
Normal file
67
normal/common/common.go
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/IBM/sarama"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type YaHuRes struct {
|
||||||
|
Rate float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetExchangeRate(nowCurrency, targetCurrency string) (float64, error) {
|
||||||
|
|
||||||
|
res, err := http.Get("http://www.google.com?now=" + nowCurrency + "&targetCurrency=" + targetCurrency)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
res.Body.Close()
|
||||||
|
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
log.Fatalf("Response failed with status code: %d and\nbody: %s\n", res.StatusCode, body)
|
||||||
|
return 0, errors.New(fmt.Sprintf("Response failed with status code: %d and\nbody: %s\n", res.StatusCode, body))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var yahuRes YaHuRes
|
||||||
|
err = json.Unmarshal(body, &yahuRes)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return yahuRes.Rate, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func SendKafka(key string, info string) error {
|
||||||
|
config := sarama.NewConfig()
|
||||||
|
config.Producer.RequiredAcks = sarama.WaitForAll
|
||||||
|
config.Producer.Retry.Max = 5
|
||||||
|
config.Producer.Return.Successes = true
|
||||||
|
|
||||||
|
producer, err := sarama.NewSyncProducer([]string{"localhost:9092"}, config)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to create producer:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer producer.Close()
|
||||||
|
|
||||||
|
message := &sarama.ProducerMessage{
|
||||||
|
Topic: key,
|
||||||
|
Value: sarama.StringEncoder(info),
|
||||||
|
}
|
||||||
|
_, _, err = producer.SendMessage(message)
|
||||||
|
return err
|
||||||
|
}
|
20
normal/controller/transfer.go
Normal file
20
normal/controller/transfer.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/common/vo"
|
||||||
|
"dddexample/normal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/gin-gonic/gin/binding"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Transfer 创建订单
|
||||||
|
func Transfer(c *gin.Context) {
|
||||||
|
var req vo.TransferRequest
|
||||||
|
|
||||||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
service.Transfer(req.SourceUserId,req.TargetAccountNumber,req.TargetAmount,req.TargetCurrency)
|
||||||
|
return
|
||||||
|
}
|
13
normal/model/common.go
Normal file
13
normal/model/common.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
func SelectByUserId(id int) Account {
|
||||||
|
var obj Account
|
||||||
|
DB.Model(&Account{}).Find(&obj,id)
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
func SelectByAccountNumber(phone string) Account {
|
||||||
|
var obj Account
|
||||||
|
DB.Model(&Account{}).Where(&Account{TelNum: phone}).Find(&obj)
|
||||||
|
return obj
|
||||||
|
}
|
56
normal/model/init.go
Normal file
56
normal/model/init.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/driver/mysql"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var DB *gorm.DB
|
||||||
|
|
||||||
|
type MysqlConfig struct {
|
||||||
|
Db string
|
||||||
|
DbHost string
|
||||||
|
DbPort string
|
||||||
|
DbUser string
|
||||||
|
DbPassWord string
|
||||||
|
DbName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadEnv(config MysqlConfig) {
|
||||||
|
|
||||||
|
//MySQL数据库
|
||||||
|
path := strings.Join([]string{config.DbUser, ":", config.DbPassWord, "@tcp(", config.DbHost, ":",
|
||||||
|
config.DbPort, ")/", config.DbName, "?charset=utf8&parseTime=true&loc=Local"}, "")
|
||||||
|
|
||||||
|
fmt.Println(path)
|
||||||
|
//连接数据库
|
||||||
|
Database(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Database(conn string) {
|
||||||
|
db, err := gorm.Open(mysql.New(mysql.Config{
|
||||||
|
DSN: conn, // DSN data source name
|
||||||
|
DefaultStringSize: 256, // string 类型字段的默认长度
|
||||||
|
DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
|
||||||
|
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
|
||||||
|
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
|
||||||
|
SkipInitializeWithVersion: false, // 根据版本自动配置
|
||||||
|
}), &gorm.Config{
|
||||||
|
NamingStrategy: schema.NamingStrategy{
|
||||||
|
SingularTable: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
sqlDB, _ := db.DB()
|
||||||
|
sqlDB.SetMaxIdleConns(20) //设置连接池,空闲
|
||||||
|
sqlDB.SetMaxOpenConns(100) //打开
|
||||||
|
sqlDB.SetConnMaxLifetime(time.Second * 30)
|
||||||
|
DB = db
|
||||||
|
}
|
19
normal/model/user.go
Normal file
19
normal/model/user.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/plugin/soft_delete"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
//Account 用户模型
|
||||||
|
type Account struct {
|
||||||
|
ID uint `gorm:"primarykey"`
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11)" json:"deletedAt"`
|
||||||
|
Account string `gorm:"unique"`
|
||||||
|
TelNum string
|
||||||
|
Currency string
|
||||||
|
Amount float64
|
||||||
|
DailyLimit float64
|
||||||
|
}
|
141
normal/service/transfer.go
Normal file
141
normal/service/transfer.go
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/normal/common"
|
||||||
|
model2 "dddexample/normal/model"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/IBM/sarama"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TransferOld(sourceUserId int, targetAccountNumber string, targetAmount float64, targetCurrency string) error {
|
||||||
|
// 1. 从数据库读取数据,忽略所有校验逻辑如账号是否存在等,错误忽略
|
||||||
|
var targetAccountDO, sourceAccountDO model2.Account
|
||||||
|
model2.DB.Model(&model2.Account{}).Find(&sourceAccountDO, sourceUserId)
|
||||||
|
model2.DB.Model(&model2.Account{}).Where(&model2.Account{TelNum: targetAccountNumber}).Find(&targetAccountDO)
|
||||||
|
|
||||||
|
// 2. 业务参数校验
|
||||||
|
if targetAccountDO.Currency != targetCurrency {
|
||||||
|
return errors.New("收款人货币种类与转账使用货币不同")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 获取外部数据,并且包含一定的业务逻辑 获取汇率
|
||||||
|
exchangeRate := 1.0
|
||||||
|
if sourceAccountDO.Currency != targetCurrency {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
res, err := http.Get("http://www.google.com?now=" + sourceAccountDO.Currency + "&targetCurrency=" + targetCurrency)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
res.Body.Close()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
return errors.New(fmt.Sprintf("Response failed with status code: %d and\nbody: %s\n", res.StatusCode, body))
|
||||||
|
}
|
||||||
|
|
||||||
|
var yahuRes common.YaHuRes
|
||||||
|
err = json.Unmarshal(body, &yahuRes)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
exchangeRate = yahuRes.Rate
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceAmount := targetAmount * exchangeRate
|
||||||
|
|
||||||
|
// 4. 业务参数校验
|
||||||
|
if sourceAccountDO.Amount < sourceAmount {
|
||||||
|
return errors.New("余额不足")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceAccountDO.DailyLimit < sourceAmount {
|
||||||
|
return errors.New("超出限额")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 计算新值,并且更新字段
|
||||||
|
sourceAccountDO.Amount -= sourceAmount
|
||||||
|
targetAccountDO.Amount += sourceAmount
|
||||||
|
|
||||||
|
// 6. 更新到数据库
|
||||||
|
model2.DB.Save(sourceAccountDO)
|
||||||
|
model2.DB.Save(targetAccountDO)
|
||||||
|
|
||||||
|
// 7. 发送审计消息String message = sourceUserId + "," + targetAccountNumber + "," + targetAmount + "," + targetCurrency;
|
||||||
|
//common.SendKafka("kafka", "")
|
||||||
|
config := sarama.NewConfig()
|
||||||
|
config.Producer.RequiredAcks = sarama.WaitForAll
|
||||||
|
config.Producer.Retry.Max = 5
|
||||||
|
config.Producer.Return.Successes = true
|
||||||
|
|
||||||
|
producer, err := sarama.NewSyncProducer([]string{"localhost:9092"}, config)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to create producer:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer producer.Close()
|
||||||
|
|
||||||
|
message := &sarama.ProducerMessage{
|
||||||
|
Topic: "my_topic",
|
||||||
|
Value: sarama.StringEncoder("Hello, Kafka!"),
|
||||||
|
}
|
||||||
|
_, _, err = producer.SendMessage(message)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Transfer(sourceUserId int, targetAccountNumber string, targetAmount float64, targetCurrency string) error {
|
||||||
|
// 1. 从数据库读取数据,忽略所有校验逻辑如账号是否存在等
|
||||||
|
sourceAccountDO := model2.SelectByUserId(sourceUserId)
|
||||||
|
targetAccountDO := model2.SelectByAccountNumber(targetAccountNumber)
|
||||||
|
|
||||||
|
// 2. 业务参数校验
|
||||||
|
if targetAccountDO.Currency != targetCurrency {
|
||||||
|
return errors.New("收款人货币种类与转账使用货币不同")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 获取外部数据,并且包含一定的业务逻辑 获取汇率
|
||||||
|
exchangeRate := 1.0
|
||||||
|
if sourceAccountDO.Currency != targetCurrency {
|
||||||
|
var err error
|
||||||
|
exchangeRate, err = common.GetExchangeRate(sourceAccountDO.Currency, targetCurrency)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceAmount := targetAmount * exchangeRate
|
||||||
|
|
||||||
|
// 4. 业务参数校验
|
||||||
|
if sourceAccountDO.Amount < sourceAmount {
|
||||||
|
return errors.New("余额不足")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceAccountDO.DailyLimit < sourceAmount {
|
||||||
|
return errors.New("超出限额")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 计算新值,并且更新字段
|
||||||
|
sourceAccountDO.Amount -= sourceAmount
|
||||||
|
targetAccountDO.Amount += sourceAmount
|
||||||
|
|
||||||
|
// 6. 更新到数据库
|
||||||
|
model2.DB.Save(sourceAccountDO)
|
||||||
|
model2.DB.Save(targetAccountDO)
|
||||||
|
|
||||||
|
// 7. 发送审计消息String message = sourceUserId + "," + targetAccountNumber + "," + targetAmount + "," + targetCurrency;
|
||||||
|
common.SendKafka("kafka", "")
|
||||||
|
return nil
|
||||||
|
}
|
5
pkg/application/external/exchangerage.go
vendored
Normal file
5
pkg/application/external/exchangerage.go
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package external
|
||||||
|
|
||||||
|
type QueueMsgRepository interface {
|
||||||
|
SendMsg(topic, info string) error
|
||||||
|
}
|
9
pkg/application/external/queuemsg.go
vendored
Normal file
9
pkg/application/external/queuemsg.go
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package external
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/pkg/domain/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ExchangeRateRepository interface {
|
||||||
|
GetExchangeRage(nowCurrency, nextCurrent string) (*entity.ExchangeRate, error)
|
||||||
|
}
|
11
pkg/application/repository/user.go
Normal file
11
pkg/application/repository/user.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/pkg/domain/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserRepository interface {
|
||||||
|
SelectByID(id int) *entity.AccountEntity
|
||||||
|
SelectByAccountNumber(account string) *entity.AccountEntity
|
||||||
|
UpdateAccountMoney(*entity.AccountEntity)
|
||||||
|
}
|
51
pkg/application/transfer.go
Normal file
51
pkg/application/transfer.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/pkg/application/external"
|
||||||
|
"dddexample/pkg/application/repository"
|
||||||
|
"dddexample/pkg/domain/entity"
|
||||||
|
"dddexample/pkg/domain/service"
|
||||||
|
"dddexample/pkg/infrastructure/externalimp"
|
||||||
|
"dddexample/pkg/infrastructure/repositoryimp"
|
||||||
|
)
|
||||||
|
|
||||||
|
var transferApplication *TransferApplication
|
||||||
|
|
||||||
|
type TransferApplication struct {
|
||||||
|
repository repository.UserRepository
|
||||||
|
exchangeRateRepository external.ExchangeRateRepository
|
||||||
|
queueRepository external.QueueMsgRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
transferApplication = &TransferApplication{
|
||||||
|
repository: &repositoryimp.UserRepositoryImp{},
|
||||||
|
exchangeRateRepository: &externalimp.ExchangeRage{},
|
||||||
|
queueRepository: &externalimp.KafkaQueue{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *TransferApplication) Transfer(sourceUserId int, targetAccountNumber string, targetAmount float64, targetCurrency string) error {
|
||||||
|
|
||||||
|
money := entity.Money{Amount: targetAmount, Currency: targetCurrency}
|
||||||
|
|
||||||
|
// 1. 从数据库读取数据,忽略所有校验逻辑如账号是否存在等
|
||||||
|
sourceAccountDO := a.repository.SelectByID(sourceUserId)
|
||||||
|
targetAccountDO := a.repository.SelectByAccountNumber(targetAccountNumber)
|
||||||
|
|
||||||
|
// 3. 获取外部数据,并且包含一定的业务逻辑 获取汇率
|
||||||
|
rate, _ := a.exchangeRateRepository.GetExchangeRage(sourceAccountDO.Currency, targetCurrency)
|
||||||
|
|
||||||
|
err := service.Transfer(sourceAccountDO, targetAccountDO, money, rate)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
a.repository.UpdateAccountMoney(sourceAccountDO)
|
||||||
|
a.repository.UpdateAccountMoney(targetAccountDO)
|
||||||
|
|
||||||
|
// 7. 发送审计消息String message = sourceUserId + "," + targetAccountNumber + "," + targetAmount + "," + targetCurrency;
|
||||||
|
err = a.queueRepository.SendMsg("topic", "")
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
12
pkg/domain/entity/exchange.go
Normal file
12
pkg/domain/entity/exchange.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
type ExchangeRate struct {
|
||||||
|
rage string
|
||||||
|
source string
|
||||||
|
target string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ExchangeRate) ExchageTo(money Money) Money {
|
||||||
|
return Money{}
|
||||||
|
|
||||||
|
}
|
23
pkg/domain/entity/money.go
Normal file
23
pkg/domain/entity/money.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
type Money struct {
|
||||||
|
Amount float64
|
||||||
|
Currency string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Money) Less(money float64) bool {
|
||||||
|
if a.Amount < money {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Money) Subtract(money float64) *Money {
|
||||||
|
return &Money{Amount: a.Amount - money, Currency: a.Currency}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Money) Add(money float64) *Money {
|
||||||
|
return &Money{Amount: a.Amount + money, Currency: a.Currency}
|
||||||
|
}
|
50
pkg/domain/entity/user.go
Normal file
50
pkg/domain/entity/user.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"gorm.io/plugin/soft_delete"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
//AccountEntity 用户模型
|
||||||
|
type AccountEntity struct {
|
||||||
|
ID uint
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
DeletedAt soft_delete.DeletedAt
|
||||||
|
Account string
|
||||||
|
TelNum string
|
||||||
|
Currency string
|
||||||
|
Amount *Money
|
||||||
|
DailyLimit *Money
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转出
|
||||||
|
func (a *AccountEntity) Withdraw(money Money) error {
|
||||||
|
if a.Amount.Currency != money.Currency {
|
||||||
|
return errors.New("货币不对")
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.Amount.Less(money.Amount) {
|
||||||
|
return errors.New("余额不足")
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.DailyLimit.Less(money.Amount) {
|
||||||
|
return errors.New("当日余额不足")
|
||||||
|
}
|
||||||
|
|
||||||
|
a.Amount = a.Amount.Subtract(money.Amount)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转入
|
||||||
|
func (a *AccountEntity) Deposit(money Money) error {
|
||||||
|
if a.Amount.Currency != money.Currency {
|
||||||
|
return errors.New("货币不对")
|
||||||
|
}
|
||||||
|
|
||||||
|
a.Amount = a.Amount.Add(money.Amount)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
19
pkg/domain/service/transfer.go
Normal file
19
pkg/domain/service/transfer.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import "dddexample/pkg/domain/entity"
|
||||||
|
|
||||||
|
func Transfer(sourceAccount, targetAccount *entity.AccountEntity, money entity.Money, exchangeRate *entity.ExchangeRate) (err error) {
|
||||||
|
var sourceMoney = exchangeRate.ExchageTo(money)
|
||||||
|
|
||||||
|
err = targetAccount.Deposit(money) //转入
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = sourceAccount.Withdraw(sourceMoney) //转出
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
34
pkg/infrastructure/externalimp/http.go
Normal file
34
pkg/infrastructure/externalimp/http.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package externalimp
|
||||||
|
|
||||||
|
import "dddexample/pkg/domain/entity"
|
||||||
|
|
||||||
|
type ExchangeRage struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ExchangeRage) GetExchangeRage(nowCurrency, nextCurrent string) (*entity.ExchangeRate, error) {
|
||||||
|
/*url := "https://ms.fontree.cn/mgmt/pricing/artworkPrice?tfnum=" + artworkNum
|
||||||
|
res, err := http.Get(url)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("请求错误", url, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer res.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
b, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(b, &work)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return &entity.ExchangeRate{}, nil
|
||||||
|
|
||||||
|
}
|
35
pkg/infrastructure/externalimp/http_test.go
Normal file
35
pkg/infrastructure/externalimp/http_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package externalimp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/pkg/domain/entity"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestExchangeRage_GetExchangeRage(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
nowCurrency string
|
||||||
|
nextCurrent string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want *entity.ExchangeRate
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
a := &ExchangeRage{}
|
||||||
|
got, err := a.GetExchangeRage(tt.args.nowCurrency, tt.args.nextCurrent)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("GetExchangeRage() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("GetExchangeRage() got = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
33
pkg/infrastructure/externalimp/kafka.go
Normal file
33
pkg/infrastructure/externalimp/kafka.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package externalimp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/IBM/sarama"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KafkaQueue struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *KafkaQueue) SendMsg(key, info string) error {
|
||||||
|
config := sarama.NewConfig()
|
||||||
|
config.Producer.RequiredAcks = sarama.WaitForAll
|
||||||
|
config.Producer.Retry.Max = 5
|
||||||
|
config.Producer.Return.Successes = true
|
||||||
|
|
||||||
|
producer, err := sarama.NewSyncProducer([]string{"localhost:9092"}, config)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to create producer:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer producer.Close()
|
||||||
|
|
||||||
|
message := &sarama.ProducerMessage{
|
||||||
|
Topic: key,
|
||||||
|
Value: sarama.StringEncoder(info),
|
||||||
|
}
|
||||||
|
_, _, err = producer.SendMessage(message)
|
||||||
|
|
||||||
|
return err
|
||||||
|
|
||||||
|
}
|
13
pkg/infrastructure/model/common.go
Normal file
13
pkg/infrastructure/model/common.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
func SelectByUserId(id int) Account {
|
||||||
|
var obj Account
|
||||||
|
DB.Model(&Account{}).Find(&obj,id)
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
func SelectByAccountNumber(phone string) Account {
|
||||||
|
var obj Account
|
||||||
|
DB.Model(&Account{}).Where(&Account{TelNum: phone}).Find(&obj)
|
||||||
|
return obj
|
||||||
|
}
|
56
pkg/infrastructure/model/init.go
Normal file
56
pkg/infrastructure/model/init.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/driver/mysql"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var DB *gorm.DB
|
||||||
|
|
||||||
|
type MysqlConfig struct {
|
||||||
|
Db string
|
||||||
|
DbHost string
|
||||||
|
DbPort string
|
||||||
|
DbUser string
|
||||||
|
DbPassWord string
|
||||||
|
DbName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadEnv(config MysqlConfig) {
|
||||||
|
|
||||||
|
//MySQL数据库
|
||||||
|
path := strings.Join([]string{config.DbUser, ":", config.DbPassWord, "@tcp(", config.DbHost, ":",
|
||||||
|
config.DbPort, ")/", config.DbName, "?charset=utf8&parseTime=true&loc=Local"}, "")
|
||||||
|
|
||||||
|
fmt.Println(path)
|
||||||
|
//连接数据库
|
||||||
|
Database(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Database(conn string) {
|
||||||
|
db, err := gorm.Open(mysql.New(mysql.Config{
|
||||||
|
DSN: conn, // DSN data source name
|
||||||
|
DefaultStringSize: 256, // string 类型字段的默认长度
|
||||||
|
DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
|
||||||
|
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
|
||||||
|
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
|
||||||
|
SkipInitializeWithVersion: false, // 根据版本自动配置
|
||||||
|
}), &gorm.Config{
|
||||||
|
NamingStrategy: schema.NamingStrategy{
|
||||||
|
SingularTable: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
sqlDB, _ := db.DB()
|
||||||
|
sqlDB.SetMaxIdleConns(20) //设置连接池,空闲
|
||||||
|
sqlDB.SetMaxOpenConns(100) //打开
|
||||||
|
sqlDB.SetConnMaxLifetime(time.Second * 30)
|
||||||
|
DB = db
|
||||||
|
}
|
19
pkg/infrastructure/model/user.go
Normal file
19
pkg/infrastructure/model/user.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/plugin/soft_delete"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
//Account 用户模型
|
||||||
|
type Account struct {
|
||||||
|
ID uint `gorm:"primarykey"`
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11)" json:"deletedAt"`
|
||||||
|
Account string `gorm:"unique"`
|
||||||
|
TelNum string
|
||||||
|
Currency string
|
||||||
|
Amount float64
|
||||||
|
DailyLimit float64
|
||||||
|
}
|
30
pkg/infrastructure/repositoryimp/user.go
Normal file
30
pkg/infrastructure/repositoryimp/user.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package repositoryimp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/pkg/domain/entity"
|
||||||
|
"dddexample/pkg/infrastructure/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserRepositoryImp struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UserRepositoryImp) SelectByID(id int) *entity.AccountEntity {
|
||||||
|
var accountObj model.Account
|
||||||
|
|
||||||
|
model.DB.Model(&model.Account{}).Find(&accountObj, id)
|
||||||
|
|
||||||
|
return &entity.AccountEntity{Account: accountObj.Account}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UserRepositoryImp) SelectByAccountNumber(account string) *entity.AccountEntity {
|
||||||
|
var accountObj model.Account
|
||||||
|
|
||||||
|
model.DB.Model(&model.Account{}).Where(&model.Account{Account: account}).Find(&accountObj)
|
||||||
|
|
||||||
|
return &entity.AccountEntity{Account: accountObj.Account}
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新
|
||||||
|
func (l *UserRepositoryImp) UpdateAccountMoney(*entity.AccountEntity) {
|
||||||
|
return
|
||||||
|
}
|
20
pkg/interfaces/transfer.go
Normal file
20
pkg/interfaces/transfer.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package interfaces
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dddexample/common/vo"
|
||||||
|
"dddexample/normal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/gin-gonic/gin/binding"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Transfer 创建订单
|
||||||
|
func Transfer(c *gin.Context) {
|
||||||
|
var req vo.TransferRequest
|
||||||
|
|
||||||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
service.Transfer(req.SourceUserId, req.TargetAccountNumber, req.TargetAmount, req.TargetCurrency)
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user