Compare commits
21 Commits
446688b00d
...
fc4db17eba
Author | SHA1 | Date |
---|---|---|
|
fc4db17eba | 3 years ago |
|
17b203e6f7 | 3 years ago |
|
9897f9b210 | 3 years ago |
|
eca56df27b | 3 years ago |
|
5a7bc9325c | 3 years ago |
|
03892ee537 | 3 years ago |
|
ab85aec437 | 3 years ago |
|
12b95a1fa8 | 3 years ago |
|
0f5f0e4aa6 | 3 years ago |
|
9a7235f41d | 3 years ago |
|
11ab235641 | 3 years ago |
|
66e4c2de0c | 3 years ago |
|
555f9e86e0 | 3 years ago |
|
f831add15b | 3 years ago |
|
ca8aed1fbf | 3 years ago |
|
33171fddce | 3 years ago |
|
4e2805bd71 | 3 years ago |
|
5d613b2f53 | 3 years ago |
|
c2ab4dc098 | 3 years ago |
|
dd2093bcaf | 3 years ago |
|
c84e0691da | 3 years ago |
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/payment-service.iml" filepath="$PROJECT_DIR$/.idea/payment-service.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,33 @@
|
|||||||
|
module payment
|
||||||
|
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gin-gonic/gin v1.8.1
|
||||||
|
//github.com/go-pay/gopay v1.5.86
|
||||||
|
github.com/smartwalle/alipay/v3 v3.1.8
|
||||||
|
)
|
||||||
|
|
||||||
|
require github.com/go-pay/gopay v1.5.86
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.11.1 // indirect
|
||||||
|
github.com/goccy/go-json v0.9.11 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.16 // 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.5 // indirect
|
||||||
|
github.com/smartwalle/crypto4go v1.0.2 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||||
|
golang.org/x/crypto v0.2.0 // indirect
|
||||||
|
golang.org/x/net v0.2.0 // indirect
|
||||||
|
golang.org/x/sys v0.2.0 // indirect
|
||||||
|
golang.org/x/text v0.4.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
)
|
@ -0,0 +1,109 @@
|
|||||||
|
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/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.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
|
||||||
|
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
|
||||||
|
github.com/go-pay/gopay v1.5.86 h1:+376yYIGZ75n6rBWRY+CdzQKd8PfcGNmu0J1C9PrdtQ=
|
||||||
|
github.com/go-pay/gopay v1.5.86/go.mod h1:xeGslGynQ2q9cvOo/pB5URZJ52I8yF1RgBGBD3j2qss=
|
||||||
|
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||||
|
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
|
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
|
||||||
|
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
|
||||||
|
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
|
||||||
|
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
|
||||||
|
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
|
||||||
|
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
|
||||||
|
github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
|
||||||
|
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||||
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
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/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
|
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||||
|
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
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.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||||
|
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||||
|
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
||||||
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
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.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
|
||||||
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
|
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/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||||
|
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||||
|
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||||
|
github.com/smartwalle/alipay/v3 v3.1.8 h1:4oWNZ4yPF7ezFO1hLd5jOaqyZnDRQPb6y3vS2uKR7ns=
|
||||||
|
github.com/smartwalle/alipay/v3 v3.1.8/go.mod h1:cZUMCCnsux9YAxA0/f3PWUR+7wckWtE1BqxbVRtGij0=
|
||||||
|
github.com/smartwalle/crypto4go v1.0.2 h1:9DUEOOsPhmp00438L4oBdcL8EZG1zumecft5bWj5phI=
|
||||||
|
github.com/smartwalle/crypto4go v1.0.2/go.mod h1:LQ7vCZIb7BE5+MuMtJBuO8ORkkQ01m4DXDBWPzLbkMY=
|
||||||
|
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/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
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 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
|
||||||
|
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
||||||
|
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
|
||||||
|
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
|
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
|
golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE=
|
||||||
|
golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
|
||||||
|
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/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-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
|
||||||
|
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
|
||||||
|
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
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.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||||
|
google.golang.org/protobuf v1.28.1/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-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/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=
|
@ -0,0 +1,131 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/smartwalle/alipay/v3"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 将公钥提供给支付宝(通过支付宝后台上传)对我们请求的数据进行签名验证,我们的代码中将使用私钥对请求数据签名。
|
||||||
|
// 目前新创建的支付宝应用只支持证书方式认证,已经弃用之前的公钥和私钥的方式
|
||||||
|
// 私钥:用于加密请求参数;
|
||||||
|
// 公钥:用于解密通过 私钥加密后的 请求参数。
|
||||||
|
var (
|
||||||
|
// appId
|
||||||
|
APPID = "2021000116681444"
|
||||||
|
// 应用公钥
|
||||||
|
AliAppPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp1o6GRM72PKbU299+VmOd1527hKp+//fpEPkz7yBHBCoaAAASuIaaQyuHHtJAcjVlb4XNjLoRyIXQ71rPQaucs/5qjmvyPAlfBNJhVaUAV5ZX7WtXHMAEdTBzVODP5axjY5BSzSmpvm9fNPDuaU3ayyqENP5yoHFs2zTSpnwRoh9Ct+urqfrAJRBx435OwVJ6Abv6blKcXMSRLlgq9hM5fbzFHv7OQ8QXvrsB9NA6s2PELI5hbLFuW0T8WyX4AaFIo2SHnHGludrDwKCxO3HolwjZoQKNcsZhDOG0A3kcVUowpnP3SqkbsfVId943KxvXTIouAoYYbfD6/BKcVlC/QIDAQAB"
|
||||||
|
//支付宝公钥
|
||||||
|
AliPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhA9A6B+gV6pzSv9KKUFcqMZKrFIYOamHIeviQy6KgFuWekGG7KA6agJyGaYrogTpp97NyopgORAK+D5J7bRdcJ1smkpHlyXF0P8D9H/+wZn++1TSQYWWoPJbQXX+l0Ma42O6ISckwXHeZr0tLWUaAoTnTkSAqR0e5LtAFusND6EY/pFFJONxM2Fouwb9WiNCw6J1zQDpO1Y0bxVgQy9v19N/Qw04MtPakua2BqyZctbLggA8WhusCzbTMRZCcOXdYFajPqSvVz5278K6RGKjVeDVBUuaUcA394v1I9tHIa41o8P7j0DhFfDS5Lo8npjhkxcF2wHqfzf5NH041jwAQQIDAQAB"
|
||||||
|
//私钥
|
||||||
|
PrivateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCnWjoZEzvY8ptTb335WY53XnbuEqn7/9+kQ+TPvIEcEKhoAABK4hppDK4ce0kByNWVvhc2MuhHIhdDvWs9Bq5yz/mqOa/I8CV8E0mFVpQBXllfta1ccwAR1MHNU4M/lrGNjkFLNKam+b1808O5pTdrLKoQ0/nKgcWzbNNKmfBGiH0K366up+sAlEHHjfk7BUnoBu/puUpxcxJEuWCr2Ezl9vMUe/s5DxBe+uwH00DqzY8QsjmFssW5bRPxbJfgBoUijZIeccaW52sPAoLE7ceiXCNmhAo1yxmEM4bQDeRxVSjCmc/dKqRux9Uh33jcrG9dMii4Chhht8Pr8EpxWUL9AgMBAAECggEAYsQ3QZE+Yt1bmjRUrpKSKBTSL9NICveJ75I6OffQYtXZ7fcCNS+X0qOvJhQElE8I7qUPYedNep2+CTaDUbLdxdjEShhdjENefAmN/GmKU/xw1rGMLOGaCuv7rMg6z46KHzbzhgT+zdDaag84lhnRySjE/cV8yG0qVqhFUuPjEFyMrY8lb/68P+E3P4Vm+hvdaOe10ayLmYm7YBh4Z7eSdhSxENBs+7dIG37Z2xC6FQRPm5qLrFdP03tianX71ZU/J7yky4HceqW4lIW8g4CSbWlCKewaucvnZ7q449/P/PSIbPr4KxQS8bGooQF6LGYEkRISWpYIQWBSjXvUU7PDaQKBgQDV3Hgwp93FdLU414ArdXzbklzVC3SEKdIXEBmt9s+Ec13I1xPDjM1HFezow4S/aaqi5soYyR6koVvsaXeHk+cNlphgZj6lz+p0BQvCvTrjkRFwSDdlBNuxgaiwZbjjUHZPwO42d3k2kiUwyRNcGIyDyPzo4b19D06VX2JIKdpp+wKBgQDIU8ZfQUj11Zgqx/dqd5XASGtoSQNwZPROJyLFwTMg6okgdevdoWaFgRUttPDRBhdcrtmVq7voJ35xoriKNFCSvkZc8GAVKiYgIGLXNscDKZx1EP5yc9VVbUnnTW4QXBQRB+VcLGmuh1DOPTkP+sEsTZhPM5TTMCX9HxrDtW6tZwKBgQCAlkBaGQTaTbMNC14QQ2Mgbp+MpYeYU8DzhwW5uNXLcMZqFQ/YG1fuLvu0dKLjqHgl3JiVUJAxMqgfvMZW6ZIadHsIM1Hlxt7UhZgtrjOzUq1mkrVj8wjZcPlpnrANVXrdt0ZDz5A9RKBB9hTC4ivSrU2MBPc3M7XvUFu6wheGcwKBgQCCMCeIOiZPVWuZyfDZ6TOSDb53vJOWlJVMwRRRDljK+ID7bodFtqGo+5Wm6aNjRCEko6FWKpBotFnxQb3KW2tNooiZ18Gpn4W9dS6nDLtTK9S5I70o5mxrIyZXQrPXv+9ujgIZ3+cifGAgWBtgbibiQt9MAYqjoPPfRzqem6d82wKBgQCjcqFOK7Ff0bSz6S2PzFLWyHBlrEKXI+9+9N5nS8aFB8uJduu0PqK4CXs6FqbY+6xuZ9Qdhe9j2NXoqZoJyQlb8/aL1etT+/JP0Md9Wi0v9SVnnz6Ci1RmJEjO02Q/xrpphEbK87h7YpNUI4flHR4ZCr9EmXqdXRTuXImUImc3uw=="
|
||||||
|
ApliClient, _ = alipay.New(APPID, PrivateKey, false)
|
||||||
|
)
|
||||||
|
|
||||||
|
// 初始化的init
|
||||||
|
func init() {
|
||||||
|
ApliClient.LoadAppPublicCert(AliAppPublicKey)
|
||||||
|
ApliClient.LoadAliPayPublicCert(AliPublicKey)
|
||||||
|
//证书的方式 ApliClient.LoadAliPayRootCert()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 手机端的支付 弹出选择APP 还是 H5
|
||||||
|
func TradeWapAliPay(c *gin.Context) {
|
||||||
|
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TradeAppAliPay ")
|
||||||
|
var pay = alipay.TradeWapPay{}
|
||||||
|
pay.TotalAmount = "11.0"
|
||||||
|
pay.OutTradeNo = time.Now().String()
|
||||||
|
//支付之后 支付宝回调的API
|
||||||
|
//pay.ReturnURL = "http://127.0.0.1:8086/return"
|
||||||
|
pay.NotifyURL = "http://jixa9i.natappfree.cc/return"
|
||||||
|
pay.Body = "测试APP订单"
|
||||||
|
pay.Subject = "商品标题"
|
||||||
|
res, err := ApliClient.TradeWapPay(pay)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("支付失败 :", err)
|
||||||
|
}
|
||||||
|
payURL := res.String()
|
||||||
|
payURL = strings.Replace(payURL, "&", "^&", -1)
|
||||||
|
exec.Command("cmd", "/c", "start", payURL).Start()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 网站页面扫码支付
|
||||||
|
func TradePageAlipay(c *gin.Context) {
|
||||||
|
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TradePageAlipay ")
|
||||||
|
var p = alipay.TradePagePay{}
|
||||||
|
p.NotifyURL = "http://jixa9i.natappfree.cc/return" //支付异步
|
||||||
|
//p.ReturnURL = "http://127.0.0.1:8086/return" //同步
|
||||||
|
p.Subject = "修正了中文的 Bug"
|
||||||
|
p.OutTradeNo = time.Now().String()
|
||||||
|
p.TotalAmount = "10.00"
|
||||||
|
p.ProductCode = "FAST_INSTANT_TRADE_PAY"
|
||||||
|
res, err := ApliClient.TradePagePay(p)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("支付失败 :", err)
|
||||||
|
}
|
||||||
|
payURL := res.String()
|
||||||
|
payURL = strings.Replace(payURL, "&", "^&", -1)
|
||||||
|
exec.Command("cmd", "/c", "start", payURL).Start()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回调函数
|
||||||
|
/*
|
||||||
|
gmt_create=2022-11-17+13%3A39%3A42&
|
||||||
|
charset=utf-8&
|
||||||
|
gmt_payment=2022-11-17+13%3A39%3A48&
|
||||||
|
notify_time=2022-11-17+13%3A39%3A49&
|
||||||
|
subject=%E4%BF%AE%E6%AD%A3%E4%BA%86%E4%B8%AD%E6%96%87%E7%9A%84+Bug&
|
||||||
|
sign=Q%2FqJv73maQ45zEdJfYfce9%2FeCDYx03otzJL67wetT1q%2Ft1vrVrpf8EHDpDQxKzcchDqOJ%2B1v3lDyhHwd4KUHd3z9APw%2BGzonHYgccuLNwEwaYQ8Pv7PjzFMOvS2HiHptUdYMWFXKHnYi3AE%2FuBtxGASljBuMms9jnABf1xFM4BVVhdmtSdMtlhbJ0eDNNs0pAs1tdCXdX%2FV6j%2BWi6GSU7VYMRzhzhlWYm%2FTSZao4QNqjkoY6j1G4MWx%2Fvmyk3SgItDSEpECxzO2Vt0F0slbTUJwqllkQ%2Fk323VvXFBHxHOxltpnrZfegYK%2B0mE4jcpQ9jRCnXRCDMHKI9adl6kJX9A%3D%3D&
|
||||||
|
buyer_id=2088622955228317&
|
||||||
|
invoice_amount=10.00&
|
||||||
|
version=1.0&
|
||||||
|
notify_id=2022111700222133949028310528415537&
|
||||||
|
fund_bill_list=%5B%7B%22amount%22%3A%2210.00%22%2C%22fundChannel%22%3A%22ALIPAYACCOUNT%22%7D%5D&
|
||||||
|
notify_type=trade_status_sync&
|
||||||
|
out_trade_no=2022-11-17+13%3A39%3A33.8566275+%2B0800+CST+m%3D%2B3.273247501&
|
||||||
|
total_amount=10.00&
|
||||||
|
trade_status=TRADE_SUCCESS&
|
||||||
|
trade_no=2022111722001428310502276237&
|
||||||
|
auth_app_id=2021000116681444&
|
||||||
|
receipt_amount=10.00&
|
||||||
|
point_amount=0.00&
|
||||||
|
app_id=2021000116681444&buyer_pay_
|
||||||
|
|
||||||
|
*/
|
||||||
|
func AliPayNotify(c *gin.Context) {
|
||||||
|
fmt.Println(" >>>>>>>>>>>>>>>>> AliPayNotify >>>>>>>>>>>>>>>>>")
|
||||||
|
//获取请求报文的长度
|
||||||
|
conLen := c.Request.ContentLength
|
||||||
|
//新建一个字节切片 长度
|
||||||
|
body := make([]byte, conLen)
|
||||||
|
n, _ := c.Request.Body.Read(body)
|
||||||
|
vals := string(body[0:n])
|
||||||
|
fmt.Println(vals)
|
||||||
|
//验证是否支付成功
|
||||||
|
if strings.Contains(vals, "TRADE_SUCCESS") {
|
||||||
|
kv := strings.Split(vals, "&")
|
||||||
|
var no string
|
||||||
|
for k, v := range kv {
|
||||||
|
fmt.Println(k, ":", v)
|
||||||
|
//out_trade_no=xxxx
|
||||||
|
if strings.HasPrefix(v, "out_trade_no") {
|
||||||
|
index := strings.Index(v, "=")
|
||||||
|
no = v[index+1 : len(v)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("订单:", no, "成功支付")
|
||||||
|
//grpc 处理 no
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
r := gin.Default()
|
||||||
|
r.GET("/appPay", TradeWapAliPay)
|
||||||
|
r.GET("/pagePay", TradePageAlipay)
|
||||||
|
r.POST("/return", AliPayNotify)
|
||||||
|
r.Run(":8086")
|
||||||
|
}
|
@ -1,60 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
_ "github.com/spf13/viper/remote"
|
|
||||||
"gorm.io/driver/mysql"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/logger"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetConsulConfig(url string, fileKey string) (*viper.Viper, error) {
|
|
||||||
conf := viper.New()
|
|
||||||
conf.AddRemoteProvider("consul", url, fileKey)
|
|
||||||
conf.SetConfigType("json")
|
|
||||||
err := conf.ReadRemoteConfig()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("viper conf err :", err)
|
|
||||||
}
|
|
||||||
return conf, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
{
|
|
||||||
"host": "192.168.137.131",
|
|
||||||
"port": "3306",
|
|
||||||
"user": "root",
|
|
||||||
"pwd": "mashibing123",
|
|
||||||
"database": "user_center"
|
|
||||||
}
|
|
||||||
**/
|
|
||||||
|
|
||||||
// type MySQLConfig struct {
|
|
||||||
// Host string `json:"host"`
|
|
||||||
// Post string `json:"port"`
|
|
||||||
// User string `json:"user"`
|
|
||||||
// Pwd string `json:"pwd"`
|
|
||||||
// Database string `json:"database"`
|
|
||||||
// }
|
|
||||||
|
|
||||||
func GetMysqlFromConsul(vip *viper.Viper) (db *gorm.DB, err error) {
|
|
||||||
newLogger := logger.New(
|
|
||||||
log.New(os.Stdout, "\r\n", log.LstdFlags),
|
|
||||||
logger.Config{
|
|
||||||
SlowThreshold: time.Second,
|
|
||||||
LogLevel: logger.Info,
|
|
||||||
Colorful: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
str := vip.GetString("user") + ":" + vip.GetString("pwd") + "@tcp(" + vip.GetString("host") + ":" + vip.GetString("port") + ")/" + vip.GetString("database") + "?charset=utf8mb4&parseTime=True&loc=Local"
|
|
||||||
db, errr := gorm.Open(mysql.Open(str), &gorm.Config{Logger: newLogger}) //"root:mashibing123@tcp(8.142.25.43:3306)/user_center?charset=utf8mb4&parseTime=True&loc=Local"), &gorm.Config{Logger: newLogger})
|
|
||||||
if errr != nil {
|
|
||||||
log.Println("db err :", errr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return db, nil
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
jaeger "github.com/uber/jaeger-client-go"
|
|
||||||
"github.com/uber/jaeger-client-go/config"
|
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
@Auth:ShenZ
|
|
||||||
@Description: Jaeger的实列化方法
|
|
||||||
*/
|
|
||||||
func NewTracer(serviceName string, addr string) (opentracing.Tracer, io.Closer, error) {
|
|
||||||
cfg := &config.Configuration{
|
|
||||||
ServiceName: serviceName,
|
|
||||||
Sampler: &config.SamplerConfig{
|
|
||||||
Type: jaeger.SamplerTypeConst,
|
|
||||||
Param: 1,
|
|
||||||
},
|
|
||||||
Reporter: &config.ReporterConfig{
|
|
||||||
BufferFlushInterval: 1 * time.Second,
|
|
||||||
LogSpans: true,
|
|
||||||
LocalAgentHostPort: addr,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return cfg.NewTracer()
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
//小写
|
|
||||||
func Md5Encode(data string) string {
|
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(data))
|
|
||||||
tempStr := h.Sum(nil)
|
|
||||||
return hex.EncodeToString(tempStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
//大写
|
|
||||||
func MD5Encode(data string) string {
|
|
||||||
return strings.ToUpper(Md5Encode(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
//加密
|
|
||||||
func MakePassword(plainpwd, salt string) string {
|
|
||||||
return Md5Encode(plainpwd + salt)
|
|
||||||
}
|
|
||||||
|
|
||||||
//解密
|
|
||||||
func ValidPassword(plainpwd, salt string, password string) bool {
|
|
||||||
md := Md5Encode(plainpwd + salt)
|
|
||||||
fmt.Println(md + " " + password)
|
|
||||||
return md == password
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package repository
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"goproduct/domain/model"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
int32 clientId = 1;
|
|
||||||
string phone = 2;
|
|
||||||
int32 systemId = 3;
|
|
||||||
string verificationCode = 4;
|
|
||||||
**/
|
|
||||||
//接口
|
|
||||||
type IUserRepository interface {
|
|
||||||
Login(int32, string, int32, string) (*model.User, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
//创建实例
|
|
||||||
func NewUserRepository(db *gorm.DB) IUserRepository {
|
|
||||||
return &UserRepository{mysqlDB: db}
|
|
||||||
}
|
|
||||||
|
|
||||||
//数据DB
|
|
||||||
type UserRepository struct {
|
|
||||||
mysqlDB *gorm.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
//重写接口方法
|
|
||||||
func (u *UserRepository) Login(clientId int32, phone string, systemId int32, verificationCode string) (user *model.User, err error) {
|
|
||||||
user = &model.User{}
|
|
||||||
if clientId == 0 && systemId == 0 && verificationCode == "6666" {
|
|
||||||
u.mysqlDB.Where("phone = ? ", phone).Find(user)
|
|
||||||
//未找到就注册一个
|
|
||||||
if user.ID == 0 {
|
|
||||||
user.Phone = phone
|
|
||||||
u.mysqlDB.Create(&user)
|
|
||||||
//u.mysqlDB.Select("Nickname", "Avatar", "Phone", "ClientId").Create(&user)
|
|
||||||
}
|
|
||||||
return user, nil
|
|
||||||
//return user, u.mysqlDB.Where("phone = ? ", phone).Find(user).Error
|
|
||||||
} else {
|
|
||||||
return user, errors.New("参数不匹配")
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"goproduct/domain/model"
|
|
||||||
"goproduct/domain/repository"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IUserDataService interface {
|
|
||||||
Login(int32, string, int32, string) (*model.User, error)
|
|
||||||
}
|
|
||||||
type UserDataService struct {
|
|
||||||
userRepository repository.IUserRepository
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewUserDataService(userRepository repository.IUserRepository) IUserDataService {
|
|
||||||
return &UserDataService{userRepository: userRepository}
|
|
||||||
}
|
|
||||||
|
|
||||||
//重写接口方法
|
|
||||||
func (u *UserDataService) Login(clientId int32, phone string, systemId int32, verificationCode string) (user *model.User, err error) {
|
|
||||||
|
|
||||||
return u.userRepository.Login(clientId, phone, systemId, verificationCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clientId, _ := strconv.Atoi(c.Request.FormValue("clientId"))
|
|
||||||
phone := c.Request.FormValue("phone")
|
|
||||||
systemId, _ := strconv.Atoi(c.Request.FormValue("systemId"))
|
|
||||||
verificationCode := c.Request.FormValue("verificationCode")
|
|
||||||
*/
|
|
@ -1,48 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"goproduct/common"
|
|
||||||
"goproduct/domain/model"
|
|
||||||
"goproduct/domain/service"
|
|
||||||
"goproduct/proto"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
UserDataService service.IUserDataService
|
|
||||||
}
|
|
||||||
|
|
||||||
// 登录 (clientId int32, phone string, systemId int32, verifi
|
|
||||||
func (u *User) Login(ctx context.Context, loginRequest *proto.LoginRequest, loginResp *proto.LoginResp) error {
|
|
||||||
userInfo, err := u.UserDataService.Login(loginRequest.ClientId, loginRequest.GetPhone(), loginRequest.SystemId, loginRequest.VerificationCode)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println(">>>>>>>>>>>>> login success :", userInfo)
|
|
||||||
UserForResp(userInfo, loginResp)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func UserForResp(userModel *model.User, resp *proto.LoginResp) *proto.LoginResp {
|
|
||||||
timeStr := fmt.Sprintf("%d", time.Now().Unix())
|
|
||||||
resp.Token = common.Md5Encode(timeStr) //"123456"
|
|
||||||
resp.User = &proto.User{}
|
|
||||||
log.Println(userModel)
|
|
||||||
resp.User.Id = userModel.ID
|
|
||||||
resp.User.Avatar = userModel.Avatar
|
|
||||||
resp.User.ClientId = userModel.ClientId
|
|
||||||
resp.User.EmployeeId = 1 //userModel.EmployeeId
|
|
||||||
resp.User.Nickname = userModel.Nickname
|
|
||||||
resp.User.SessionId = resp.Token
|
|
||||||
resp.User.Phone = userModel.Phone
|
|
||||||
//token 过期时间
|
|
||||||
tp, _ := time.ParseDuration("1h")
|
|
||||||
tokenExpireTime := time.Now().Add(tp)
|
|
||||||
expiretimeStr := tokenExpireTime.Format("2006-01-02 15:04:05")
|
|
||||||
resp.User.TokenExpireTime = expiretimeStr
|
|
||||||
resp.User.UnionId = userModel.UnionId
|
|
||||||
return resp
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
_ "github.com/spf13/viper/remote"
|
|
||||||
"gorm.io/driver/mysql"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/logger"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetConsulConfig(url string, fileKey string) (*viper.Viper, error) {
|
|
||||||
conf := viper.New()
|
|
||||||
conf.AddRemoteProvider("consul", url, fileKey)
|
|
||||||
conf.SetConfigType("json")
|
|
||||||
err := conf.ReadRemoteConfig()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("viper conf err :", err)
|
|
||||||
}
|
|
||||||
return conf, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
{
|
|
||||||
"host": "192.168.137.131",
|
|
||||||
"port": "3306",
|
|
||||||
"user": "root",
|
|
||||||
"pwd": "mashibing123",
|
|
||||||
"database": "user_center"
|
|
||||||
}
|
|
||||||
**/
|
|
||||||
|
|
||||||
// type MySQLConfig struct {
|
|
||||||
// Host string `json:"host"`
|
|
||||||
// Post string `json:"port"`
|
|
||||||
// User string `json:"user"`
|
|
||||||
// Pwd string `json:"pwd"`
|
|
||||||
// Database string `json:"database"`
|
|
||||||
// }
|
|
||||||
|
|
||||||
func GetMysqlFromConsul(vip *viper.Viper) (db *gorm.DB, err error) {
|
|
||||||
newLogger := logger.New(
|
|
||||||
log.New(os.Stdout, "\r\n", log.LstdFlags),
|
|
||||||
logger.Config{
|
|
||||||
SlowThreshold: time.Second,
|
|
||||||
LogLevel: logger.Info,
|
|
||||||
Colorful: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
str := vip.GetString("user") + ":" + vip.GetString("pwd") + "@tcp(" + vip.GetString("host") + ":" + vip.GetString("port") + ")/" + vip.GetString("database") + "?charset=utf8mb4&parseTime=True&loc=Local"
|
|
||||||
db, errr := gorm.Open(mysql.Open(str), &gorm.Config{Logger: newLogger}) //"root:mashibing123@tcp(8.142.25.43:3306)/user_center?charset=utf8mb4&parseTime=True&loc=Local"), &gorm.Config{Logger: newLogger})
|
|
||||||
if errr != nil {
|
|
||||||
log.Println("db err :", errr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return db, nil
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
jaeger "github.com/uber/jaeger-client-go"
|
|
||||||
"github.com/uber/jaeger-client-go/config"
|
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
@Auth:ShenZ
|
|
||||||
@Description: Jaeger的实列化方法
|
|
||||||
*/
|
|
||||||
func NewTracer(serviceName string, addr string) (opentracing.Tracer, io.Closer, error) {
|
|
||||||
cfg := &config.Configuration{
|
|
||||||
ServiceName: serviceName,
|
|
||||||
Sampler: &config.SamplerConfig{
|
|
||||||
Type: jaeger.SamplerTypeConst,
|
|
||||||
Param: 1,
|
|
||||||
},
|
|
||||||
Reporter: &config.ReporterConfig{
|
|
||||||
BufferFlushInterval: 1 * time.Second,
|
|
||||||
LogSpans: true,
|
|
||||||
LocalAgentHostPort: addr,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return cfg.NewTracer()
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
"{\"ID\":33,\"Name\":\"NeSugar小巢糖创意桌面无叶风扇usb台式风扇办公室喷雾风扇冷风机\",\"ProductType\":1,\"CategoryId\":52,\"StartingPrice\":92,\"TotalStock\":0,\"MainPicture\":\"https://msb-edu-dev.oss-cn-beijing.aliyuncs.com/mall-product/productO1CN01nsp1Wk1FIYRXXUXL8_!!4023510464-0-cib.jpg\",\"RemoteAreaPostage\":10,\"SingleBuyLimit\":0,\"IsEnable\":1,\"Remark\":\"NeSugar小巢糖创意桌面无叶风扇usb台式风扇办公室喷雾风扇冷风机\",\"CreateUser\":1,\"CreateTime\":\"2022-04-30T16:55:00+08:00\",\"Up"
|
|
||||||
|
|
||||||
**/
|
|
||||||
//通过json tag 进行结构体赋值
|
|
||||||
func SwapToStruct(req, target interface{}) (err error) {
|
|
||||||
dataByte, err := json.Marshal(req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(dataByte, target)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type H struct {
|
|
||||||
Code string
|
|
||||||
Message string
|
|
||||||
TraceId string
|
|
||||||
Data interface{}
|
|
||||||
Rows interface{}
|
|
||||||
Total interface{}
|
|
||||||
SkyWalkingDynamicField string
|
|
||||||
}
|
|
||||||
|
|
||||||
func Resp(w http.ResponseWriter, code string, data interface{}, message string) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
h := H{
|
|
||||||
Code: code,
|
|
||||||
Data: data,
|
|
||||||
Message: message,
|
|
||||||
}
|
|
||||||
ret, err := json.Marshal(h)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
w.Write(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RespList(w http.ResponseWriter, code string, data interface{}, message string, rows interface{}, total interface{}, skyWalkingDynamicField string) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
h := H{
|
|
||||||
Code: code,
|
|
||||||
Data: data,
|
|
||||||
Message: message,
|
|
||||||
Rows: rows,
|
|
||||||
Total: total,
|
|
||||||
SkyWalkingDynamicField: skyWalkingDynamicField,
|
|
||||||
}
|
|
||||||
ret, err := json.Marshal(h)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
w.Write(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
200 OKLoginSuccessVO
|
|
||||||
201 Created
|
|
||||||
401 Unauthorized
|
|
||||||
403 Forbidden
|
|
||||||
404 Not Found
|
|
||||||
**/
|
|
||||||
func RespOK(w http.ResponseWriter, data interface{}, message string) {
|
|
||||||
Resp(w, "SUCCESS", data, message)
|
|
||||||
}
|
|
||||||
func RespFail(w http.ResponseWriter, data interface{}, message string) {
|
|
||||||
Resp(w, "TOKEN_FAIL", data, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
//writer data message row total field
|
|
||||||
func RespListOK(w http.ResponseWriter, data interface{}, message string, rows interface{}, total interface{}, skyWalkingDynamicField string) {
|
|
||||||
RespList(w, "SUCCESS", data, message, rows, total, skyWalkingDynamicField)
|
|
||||||
}
|
|
||||||
func RespListFail(w http.ResponseWriter, data interface{}, message string, rows interface{}, total interface{}, skyWalkingDynamicField string) {
|
|
||||||
RespList(w, "TOKEN_FAIL", data, message, rows, total, skyWalkingDynamicField)
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
@Auth:ShenZ
|
|
||||||
@Description: 用于UUID 加密算法
|
|
||||||
*/
|
|
||||||
|
|
||||||
func StringToArray(intput string) []int {
|
|
||||||
output := []int{}
|
|
||||||
for _, v := range intput {
|
|
||||||
output = append(output, int(v))
|
|
||||||
}
|
|
||||||
for i, j := 0, len(output)-1; i < j; i, j = i+1, j-1 {
|
|
||||||
output[i], output[j] = output[j], output[i]
|
|
||||||
}
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
func GetInput(intput string) <-chan int {
|
|
||||||
out := make(chan int)
|
|
||||||
go func() {
|
|
||||||
for _, b := range StringToArray(intput) {
|
|
||||||
out <- b
|
|
||||||
}
|
|
||||||
close(out)
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
func SQ(in <-chan int) <-chan int {
|
|
||||||
out := make(chan int)
|
|
||||||
var base, i float64 = 2, 0
|
|
||||||
go func() {
|
|
||||||
for n := range in {
|
|
||||||
out <- (n - 48) * int(math.Pow(base, i))
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
close(out)
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func ToInt(intput string) int {
|
|
||||||
//intput := "101010101110110"
|
|
||||||
c := GetInput(intput)
|
|
||||||
out := SQ(c)
|
|
||||||
sum := 0
|
|
||||||
for o := range out {
|
|
||||||
sum += o
|
|
||||||
}
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
||||||
// int 转 二进制的字符串
|
|
||||||
func ConverToBinary(n int) string {
|
|
||||||
res := ""
|
|
||||||
for ; n > 0; n /= 2 {
|
|
||||||
lsb := n % 2
|
|
||||||
res = strconv.Itoa(lsb) + res
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/product-service.iml" filepath="$PROJECT_DIR$/.idea/product-service.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true">
|
||||||
|
<buildTags>
|
||||||
|
<option name="goVersion" value="go1.17" />
|
||||||
|
</buildTags>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectTasksOptions">
|
||||||
|
<enabled-global>
|
||||||
|
<option value="go fmt" />
|
||||||
|
</enabled-global>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,349 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/afex/hystrix-go/hystrix"
|
||||||
|
consul "github.com/asim/go-micro/plugins/registry/consul/v4"
|
||||||
|
"github.com/dtm-labs/dtm/client/dtmcli"
|
||||||
|
"github.com/go-micro/plugins/v4/wrapper/select/roundrobin"
|
||||||
|
opentracing2 "github.com/go-micro/plugins/v4/wrapper/trace/opentracing"
|
||||||
|
"github.com/lithammer/shortuuid/v3"
|
||||||
|
"github.com/opentracing/opentracing-go"
|
||||||
|
"go-micro.dev/v4/client"
|
||||||
|
"go-micro.dev/v4/web"
|
||||||
|
"strconv"
|
||||||
|
//"goproduct/common"
|
||||||
|
common "git.mashibing.com/msb_47094/shopping-comm"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"trade-order/proto"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-micro.dev/v4"
|
||||||
|
"go-micro.dev/v4/registry"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取远程服务的客户端
|
||||||
|
func main() {
|
||||||
|
resp := &proto.AddTradeOrderResp{}
|
||||||
|
router := gin.Default()
|
||||||
|
//注册到consul
|
||||||
|
consulReg := consul.NewRegistry(func(options *registry.Options) {
|
||||||
|
options.Addrs = []string{common.ConsulReistStr}
|
||||||
|
})
|
||||||
|
//初始化链路追踪的jaeper
|
||||||
|
t, io, err := common.NewTracer("shop-cart-client", common.ConsulIp+":6831")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
defer io.Close()
|
||||||
|
opentracing.SetGlobalTracer(t)
|
||||||
|
|
||||||
|
//熔断器
|
||||||
|
hystrixStreamHandler := hystrix.NewStreamHandler()
|
||||||
|
hystrixStreamHandler.Start()
|
||||||
|
go func() {
|
||||||
|
err := http.ListenAndServe(net.JoinHostPort(common.QSIp, "9097"), hystrixStreamHandler)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
rpcServer := micro.NewService(
|
||||||
|
//micro.Name("shop-product-client"),
|
||||||
|
micro.Registry(consulReg), //服务发现
|
||||||
|
micro.WrapClient(opentracing2.NewClientWrapper(opentracing.GlobalTracer())),
|
||||||
|
//加入熔断器
|
||||||
|
micro.WrapClient(NewClientHystrixWrapper()),
|
||||||
|
//负载均衡
|
||||||
|
micro.WrapClient(roundrobin.NewClientWrapper()),
|
||||||
|
)
|
||||||
|
//AddCartClient := proto.NewAddCartService("shop-cart", rpcServer.Client())
|
||||||
|
UpdateCartClient := proto.NewUpdateCartService("shop-cart", rpcServer.Client())
|
||||||
|
//ShowProductDetailClient := proto.NewShowProductDetailService("shop-product", rpcServer.Client())
|
||||||
|
//ShowDetailSkuClient := proto.NewShowDetailSkuService("shop-product", rpcServer.Client())
|
||||||
|
GetUserTokenClient := proto.NewGetUserTokenService("shop-user", rpcServer.Client())
|
||||||
|
GetOrderTotalClient := proto.NewGetOrderTotalService("shop-cart", rpcServer.Client())
|
||||||
|
AddTraderClient := proto.NewAddTradeOrderService("trade-order", rpcServer.Client())
|
||||||
|
UpdateTraderClient := proto.NewUpdateTradeOrderService("trade-order", rpcServer.Client())
|
||||||
|
FindCartClient := proto.NewFindCartService("shop-cart", rpcServer.Client())
|
||||||
|
//开始拆分 DTM服务
|
||||||
|
|
||||||
|
router.POST("/updateCart", func(c *gin.Context) {
|
||||||
|
req := &proto.UpdateCartReq{}
|
||||||
|
if err := c.BindJSON(req); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
req.IsDeleted = true
|
||||||
|
_, err := UpdateCartClient.UpdateCart(context.TODO(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("/updateCart err ", err)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "删除购物车失败!"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"updateCart": "SUCCESS", "Message": "删除购物车成功!"})
|
||||||
|
})
|
||||||
|
router.POST("/updateCart-compensate", func(c *gin.Context) {
|
||||||
|
req := &proto.UpdateCartReq{}
|
||||||
|
if err := c.BindJSON(req); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
req.IsDeleted = false
|
||||||
|
_, err := UpdateCartClient.UpdateCart(context.TODO(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("/updateCart err ", err)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "回滚购物车失败!"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"updateCart-compensate": "SUCCESS", "Message": "回滚购物车成功!"})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.POST("/addTrade", func(c *gin.Context) {
|
||||||
|
req := &proto.AddTradeOrderReq{}
|
||||||
|
if err := c.BindJSON(req); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
_, err := AddTraderClient.AddTradeOrder(context.TODO(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("/addTrade err ", err)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "新增订单失败!"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"addTrade": "SUCCESS", "Message": "新增订单成功!"})
|
||||||
|
})
|
||||||
|
router.POST("/addTrade-compensate", func(c *gin.Context) {
|
||||||
|
req := &proto.AddTradeOrderReq{}
|
||||||
|
if err := c.BindJSON(req); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
req.TradeOrder.IsDeleted = true
|
||||||
|
_, err := UpdateTraderClient.UpdateTradeOrder(context.TODO(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("/addTrade err ", err)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "回滚订单失败!"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"addTrade-compensate": "SUCCESS", "Message": "回滚订单成功!"})
|
||||||
|
})
|
||||||
|
|
||||||
|
//新增订单API
|
||||||
|
router.GET("/cartAdvanceOrder", func(c *gin.Context) {
|
||||||
|
//开始检验登录
|
||||||
|
uuid := c.Request.Header["Uuid"][0]
|
||||||
|
cc := common.GetInput(uuid)
|
||||||
|
out := common.SQ(cc)
|
||||||
|
sum := 0
|
||||||
|
for o := range out {
|
||||||
|
sum += o
|
||||||
|
}
|
||||||
|
//Token校验
|
||||||
|
//拼接请求信息
|
||||||
|
tokenReq := &proto.TokenReq{
|
||||||
|
Uuid: uuid,
|
||||||
|
}
|
||||||
|
//响应
|
||||||
|
tokenResp, err := GetUserTokenClient.GetUserToken(context.TODO(), tokenReq)
|
||||||
|
if err != nil || tokenResp.IsLogin == false {
|
||||||
|
log.Println("GetUserToken err : ", err)
|
||||||
|
common.RespFail(c.Writer, tokenResp, "未登录!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//拼接请求信息
|
||||||
|
log.Println("GetUserToken success : ", tokenResp)
|
||||||
|
//结束检验登录
|
||||||
|
|
||||||
|
//开始订单插入
|
||||||
|
tempStr := c.Request.FormValue("cartIds") // 12,355,666
|
||||||
|
cartIds := common.SplitToInt32List(tempStr, ",")
|
||||||
|
isVirtual, _ := strconv.ParseBool(c.Request.FormValue("isVirtual"))
|
||||||
|
recipientAddressId, _ := strconv.Atoi(c.Request.FormValue("recipientAddressId"))
|
||||||
|
|
||||||
|
//统计价格
|
||||||
|
totalReq := &proto.OrderTotalReq{
|
||||||
|
CartIds: cartIds,
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始校验 cart
|
||||||
|
findCartReq := &proto.FindCartReq{
|
||||||
|
Id: cartIds[0],
|
||||||
|
}
|
||||||
|
cart, err := FindCartClient.FindCart(context.TODO(), findCartReq)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("FindCart err : ", err)
|
||||||
|
common.RespFail(c.Writer, tokenResp, "查询购物车失败!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cart.ShoppingCart.IsDeleted {
|
||||||
|
common.RespFail(c.Writer, tokenResp, " 购物车已失效!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//结束cart的状态校验
|
||||||
|
totalPriceResp, _ := GetOrderTotalClient.GetOrderTotal(context.TODO(), totalReq)
|
||||||
|
log.Println("totalPrice>>>>>>>>>>>>>>>>>>>>>>>> ", totalPriceResp)
|
||||||
|
//构建tradeOrder
|
||||||
|
tradeOrder := &proto.TradeOrder{}
|
||||||
|
tradeOrder.UserId = int32(sum)
|
||||||
|
tradeOrder.CreateUser = int32(sum)
|
||||||
|
tradeOrder.OrderStatus = 1
|
||||||
|
tradeOrder.TotalAmount = totalPriceResp.TotalPrice
|
||||||
|
req := &proto.AddTradeOrderReq{
|
||||||
|
CartIds: cartIds,
|
||||||
|
IsVirtual: isVirtual,
|
||||||
|
RecipientAddressId: int32(recipientAddressId),
|
||||||
|
TradeOrder: tradeOrder,
|
||||||
|
}
|
||||||
|
updateCartReq := &proto.UpdateCartReq{
|
||||||
|
Id: cartIds[0],
|
||||||
|
}
|
||||||
|
|
||||||
|
//全局事务
|
||||||
|
gid := shortuuid.New()
|
||||||
|
saga := dtmcli.NewSaga(common.DtmServer, gid).
|
||||||
|
Add(common.QSBusi+"/updateCart", common.QSBusi+"/updateCart-compensate", updateCartReq).
|
||||||
|
Add(common.QSBusi+"/addTrade", common.QSBusi+"/addTrade-compensate", req)
|
||||||
|
err = saga.Submit()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("saga submit err :", err)
|
||||||
|
common.RespFail(c.Writer, resp, "添加失败")
|
||||||
|
}
|
||||||
|
log.Println(" /saga submit submit :", gid)
|
||||||
|
////writer data message row total field
|
||||||
|
common.RespOK(c.Writer, resp, "请求成功")
|
||||||
|
|
||||||
|
})
|
||||||
|
//router.POST("/addCart-compensate", func(c *gin.Context) {
|
||||||
|
// req := &proto.AddCartReq{}
|
||||||
|
// if err := c.BindJSON(req); err != nil {
|
||||||
|
// log.Fatalln(err)
|
||||||
|
// }
|
||||||
|
// req.Id = CartId
|
||||||
|
// resp, err = UpdateCartClient.UpdateCart(context.TODO(), req)
|
||||||
|
// CartId = resp.ID
|
||||||
|
// if err != nil {
|
||||||
|
// log.Println("/addCart-compensate err ", err)
|
||||||
|
// c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "删除购物车失败!"})
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// c.JSON(http.StatusOK, gin.H{"addCart-compensate": "SUCCESS", "Message": "删除购物车成功!"})
|
||||||
|
//})
|
||||||
|
//
|
||||||
|
//router.GET("/addShoppingCart", func(c *gin.Context) {
|
||||||
|
// number, _ := strconv.Atoi(c.Request.FormValue("number"))
|
||||||
|
// productId, _ := strconv.Atoi(c.Request.FormValue("productId"))
|
||||||
|
// productSkuId, _ := strconv.Atoi(c.Request.FormValue("productSkuId"))
|
||||||
|
// uuid := c.Request.Header["Uuid"][0]
|
||||||
|
// cc := common.GetInput(uuid)
|
||||||
|
// out := common.SQ(cc)
|
||||||
|
// sum := 0
|
||||||
|
// for o := range out {
|
||||||
|
// sum += o
|
||||||
|
// }
|
||||||
|
// //Token校验
|
||||||
|
// //拼接请求信息
|
||||||
|
// tokenReq := &proto.TokenReq{
|
||||||
|
// Uuid: uuid,
|
||||||
|
// }
|
||||||
|
// //响应
|
||||||
|
// tokenResp, err := GetUserTokenClient.GetUserToken(context.TODO(), tokenReq)
|
||||||
|
// //拼接请求信息
|
||||||
|
// respErr := &proto.AddCartResp{}
|
||||||
|
// if err != nil || tokenResp.IsLogin == false {
|
||||||
|
// log.Println("GetUserToken err : ", err)
|
||||||
|
// common.RespFail(c.Writer, respErr, "未登录!")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// log.Println("GetUserToken success : ", tokenResp)
|
||||||
|
//
|
||||||
|
// //拼接请求信息
|
||||||
|
// req := &proto.AddCartReq{
|
||||||
|
// Number: int32(number),
|
||||||
|
// ProductId: int32(productId),
|
||||||
|
// ProductSkuId: int32(productSkuId),
|
||||||
|
// UserId: int32(sum),
|
||||||
|
// }
|
||||||
|
// resp := &proto.AddCartResp{}
|
||||||
|
// //商品详情
|
||||||
|
// reqDetail := &proto.ProductDetailReq{
|
||||||
|
// Id: int32(productId),
|
||||||
|
// }
|
||||||
|
// respDetail, err := ShowProductDetailClient.ShowProductDetail(context.TODO(), reqDetail)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Println("ShowProductDetail err : ", err)
|
||||||
|
// common.RespFail(c.Writer, respErr, "查询商品详情失败!")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// if respDetail != nil {
|
||||||
|
// req.ProductName = respDetail.ProductDetail[0].Name
|
||||||
|
// req.ProductMainPicture = respDetail.ProductDetail[0].MainPicture
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //log.Println(" /ShowProductDetail resp :", respDetail)
|
||||||
|
// //SKU详情
|
||||||
|
// reqDetail.Id = req.ProductSkuId
|
||||||
|
// respSkuDetail, err := ShowDetailSkuClient.ShowDetailSku(context.TODO(), reqDetail)
|
||||||
|
// //log.Println(" /ShowDetailSku resp :", respSkuDetail)
|
||||||
|
// //添加购物车 远程调用服务
|
||||||
|
// //log.Println(" /AddCart req :", req)
|
||||||
|
//
|
||||||
|
// if respSkuDetail.ProductSku[0].Stock < req.Number {
|
||||||
|
// common.RespFail(c.Writer, &proto.AddCartResp{}, "库存不足,添加失败")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// sku := respSkuDetail.ProductSku[0]
|
||||||
|
// sku.Stock -= req.Number
|
||||||
|
// Number = req.Number //
|
||||||
|
// updateSkuReq := &proto.UpdateSkuReq{
|
||||||
|
// ProductSku: sku,
|
||||||
|
// }
|
||||||
|
// resp.ProductSkuSimple = respSkuDetail.ProductSku[0]
|
||||||
|
// resp.ProductSimple = respDetail.ProductDetail[0]
|
||||||
|
//
|
||||||
|
// //全局事务
|
||||||
|
// gid := shortuuid.New()
|
||||||
|
// saga := dtmcli.NewSaga(DtmServer, gid).
|
||||||
|
// Add(QSBusi+"/updateSku", QSBusi+"/updateSku-compensate", updateSkuReq).
|
||||||
|
// Add(QSBusi+"/addCart", QSBusi+"/addCart-compensate", req)
|
||||||
|
// err = saga.Submit()
|
||||||
|
// if err != nil {
|
||||||
|
// log.Println("saga submit err :", err)
|
||||||
|
// common.RespFail(c.Writer, resp, "添加失败")
|
||||||
|
// }
|
||||||
|
// log.Println(" /saga submit submit :", gid)
|
||||||
|
// ////writer data message row total field
|
||||||
|
// common.RespOK(c.Writer, resp, "请求成功")
|
||||||
|
//})
|
||||||
|
|
||||||
|
service := web.NewService(
|
||||||
|
web.Address(":6669"),
|
||||||
|
web.Name("trade-order-client"),
|
||||||
|
web.Registry(consulReg),
|
||||||
|
web.Handler(router),
|
||||||
|
)
|
||||||
|
//启动服务
|
||||||
|
service.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientWrapper struct {
|
||||||
|
client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c clientWrapper) Call(ctx context.Context, req client.Request, resp interface{}, opts ...client.CallOption) error {
|
||||||
|
return hystrix.Do(req.Service()+"."+req.Endpoint(), func() error {
|
||||||
|
//正常执行
|
||||||
|
fmt.Println("call success ", req.Service()+"."+req.Endpoint())
|
||||||
|
return c.Client.Call(ctx, req, resp, opts...)
|
||||||
|
}, func(err error) error {
|
||||||
|
fmt.Println("call err :", err)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClientHystrixWrapper() client.Wrapper {
|
||||||
|
return func(i client.Client) client.Client {
|
||||||
|
return &clientWrapper{i}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type TraderOrder struct {
|
||||||
|
//gorm.Model
|
||||||
|
ID int32 `json:"id"`
|
||||||
|
OrderNo string `json:"orderNo"`
|
||||||
|
UserId int32 `gorm:"default:1" json:"userId"`
|
||||||
|
TotalAmount float32 `gorm:"total_amount" json:"totalAmount"`
|
||||||
|
ShippingAmount float32 `gorm:"shipping_amount" json:"shippingAmount"`
|
||||||
|
DiscountAmount float32 `gorm:"discount_amount" json:"discountAmount"`
|
||||||
|
PayAmount float32 `gorm:"pay_amount" json:"payAmount"`
|
||||||
|
RefundAmount float32 `gorm:"refund_amount" json:"refundAmount"`
|
||||||
|
SubmitTime time.Time `json:"submitTime"`
|
||||||
|
ExpireTime time.Time `json:"expireTime"`
|
||||||
|
AutoReceiveTime time.Time `json:"autoReceiveTime"`
|
||||||
|
ReceiveTime time.Time `json:"receiveTime"`
|
||||||
|
AutoPraise time.Time `json:"autoPraise"`
|
||||||
|
AfterSaleDeadlineTime time.Time `json:"afterSaleDeadlineTime"`
|
||||||
|
OrderStatus int32 `gorm:"default:1" json:"orderStatus"`
|
||||||
|
OrderSource int32 `gorm:"default:6" json:"orderSource"`
|
||||||
|
CancelReason int32 `gorm:"cancel_reason" json:"cancelReason"`
|
||||||
|
OrderType int32 `gorm:"default:1" json:"orderType"`
|
||||||
|
CreateUser int32 `gorm:"default:1" json:"createUser"`
|
||||||
|
CreateTime time.Time `json:"createTime"`
|
||||||
|
UpdateUser int32 `json:"updateUser"`
|
||||||
|
UpdateTime time.Time `json:"updateTime"`
|
||||||
|
IsDeleted bool `json:"isDeleted"`
|
||||||
|
PayType int32 `gorm:"default:1" json:"payType"`
|
||||||
|
IsPackageFree int32 `gorm:"default:1" json:"isPackageFree"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (table *TraderOrder) TableName() string {
|
||||||
|
return "trade_order"
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"trade-order/domain/model"
|
||||||
|
"trade-order/proto"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
int32 clientId = 1;
|
||||||
|
string phone = 2;
|
||||||
|
int32 systemId = 3;
|
||||||
|
string verificationCode = 4;
|
||||||
|
**/
|
||||||
|
//接口
|
||||||
|
type ITradeRepository interface {
|
||||||
|
AddTradeOrder(req *proto.AddTradeOrderReq) (*model.TraderOrder, error)
|
||||||
|
UpdateTradeOrder(req *proto.AddTradeOrderReq) (*model.TraderOrder, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建实例
|
||||||
|
func NewTradeRepository(db *gorm.DB) ITradeRepository {
|
||||||
|
return &TradeRepository{mysqlDB: db}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据DB
|
||||||
|
type TradeRepository struct {
|
||||||
|
mysqlDB *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func SwapToStruct(req, target interface{}) (err error) {
|
||||||
|
dataByte, err := json.Marshal(req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(dataByte, target)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增订单
|
||||||
|
func (u *TradeRepository) AddTradeOrder(req *proto.AddTradeOrderReq) (obj *model.TraderOrder, err error) {
|
||||||
|
trade := &model.TraderOrder{}
|
||||||
|
err = SwapToStruct(req.TradeOrder, trade)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("SwapToStruct err :", err)
|
||||||
|
}
|
||||||
|
log.Println("SwapToStruct trade :", trade)
|
||||||
|
now := time.Now()
|
||||||
|
trade.CreateTime = now //
|
||||||
|
trade.SubmitTime = now
|
||||||
|
tp, _ := time.ParseDuration("30m")
|
||||||
|
trade.ExpireTime = now.Add(tp) //订单失效时间 30m后
|
||||||
|
trade.OrderNo = getOrderNo(now, trade.UserId)
|
||||||
|
|
||||||
|
tb := u.mysqlDB.Create(&trade)
|
||||||
|
//err = errors.New("400", "测试异常", 400)
|
||||||
|
fmt.Println("repository AddTradeOrder >>>> ", trade)
|
||||||
|
return trade, tb.Error //err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改订单
|
||||||
|
func (u *TradeRepository) UpdateTradeOrder(req *proto.AddTradeOrderReq) (obj *model.TraderOrder, err error) {
|
||||||
|
trade := model.TraderOrder{}
|
||||||
|
trade.UpdateTime = time.Now() //
|
||||||
|
tb := u.mysqlDB.Model(&model.TraderOrder{}).
|
||||||
|
Where("id = ?", trade.ID).
|
||||||
|
Updates(&trade)
|
||||||
|
//Update("order_status", trade.OrderStatus)
|
||||||
|
//err = errors.New("400", "测试异常", 400)
|
||||||
|
fmt.Println("repository UpdateTradeOrder >>>> ", trade)
|
||||||
|
return &trade, tb.Error //err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生产 订单号 Y2022 06 27 11 00 53 948 97 103564
|
||||||
|
//
|
||||||
|
// 年 月 日 时 分 秒 毫秒 ID 随机数
|
||||||
|
func getOrderNo(time2 time.Time, userID int32) string {
|
||||||
|
var tradeNo string
|
||||||
|
tempNum := strconv.Itoa(rand.Intn(999999-100000+1) + 100000)
|
||||||
|
tradeNo = "Y" + time2.Format("20060102150405.000") + strconv.Itoa(int(userID)) + tempNum
|
||||||
|
tradeNo = strings.Replace(tradeNo, ".", "", -1)
|
||||||
|
return tradeNo
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"trade-order/domain/model"
|
||||||
|
"trade-order/domain/repository"
|
||||||
|
"trade-order/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ITradeOrderService interface {
|
||||||
|
AddTradeOrder(req *proto.AddTradeOrderReq) (obj *model.TraderOrder, err error)
|
||||||
|
UpdateTradeOrder(req *proto.AddTradeOrderReq) (obj *model.TraderOrder, err error)
|
||||||
|
}
|
||||||
|
type TradeOrderService struct {
|
||||||
|
tradeRepository repository.ITradeRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTradeOrderService(cartRepository repository.ITradeRepository) ITradeOrderService {
|
||||||
|
return &TradeOrderService{tradeRepository: cartRepository}
|
||||||
|
}
|
||||||
|
|
||||||
|
// "number": 0,
|
||||||
|
//
|
||||||
|
// "productId": 0,
|
||||||
|
// "productSkuId": 0
|
||||||
|
//
|
||||||
|
// 重写接口方法
|
||||||
|
func (u *TradeOrderService) AddTradeOrder(req *proto.AddTradeOrderReq) (obj *model.TraderOrder, err error) {
|
||||||
|
return u.tradeRepository.AddTradeOrder(req)
|
||||||
|
}
|
||||||
|
func (u *TradeOrderService) UpdateTradeOrder(req *proto.AddTradeOrderReq) (obj *model.TraderOrder, err error) {
|
||||||
|
return u.tradeRepository.AddTradeOrder(req)
|
||||||
|
}
|
@ -0,0 +1,163 @@
|
|||||||
|
module trade-order
|
||||||
|
|
||||||
|
go 1.17
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
|
go-micro.dev/v4 v4.8.0
|
||||||
|
google.golang.org/protobuf v1.28.1
|
||||||
|
gorm.io/gorm v1.24.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/miekg/dns v1.1.50 // indirect
|
||||||
|
golang.org/x/net v0.1.0 // indirect
|
||||||
|
golang.org/x/sync v0.1.0 // indirect
|
||||||
|
golang.org/x/sys v0.1.0 // indirect
|
||||||
|
golang.org/x/tools v0.1.12 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
git.mashibing.com/msb_47094/shopping-comm v0.0.0-20221111074328-ab1a5ce6768e
|
||||||
|
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
|
||||||
|
github.com/asim/go-micro/plugins/registry/consul/v4 v4.7.0
|
||||||
|
github.com/dtm-labs/dtm v1.16.3
|
||||||
|
github.com/gin-gonic/gin v1.8.1
|
||||||
|
github.com/go-micro/plugins/v4/wrapper/monitoring/prometheus v1.1.0
|
||||||
|
github.com/go-micro/plugins/v4/wrapper/ratelimiter/uber v1.1.0
|
||||||
|
github.com/go-micro/plugins/v4/wrapper/select/roundrobin v1.1.0
|
||||||
|
github.com/go-micro/plugins/v4/wrapper/trace/opentracing v1.1.0
|
||||||
|
github.com/lithammer/shortuuid/v3 v3.0.7
|
||||||
|
github.com/opentracing/opentracing-go v1.2.0
|
||||||
|
google.golang.org/grpc v1.50.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
cloud.google.com/go v0.105.0 // indirect
|
||||||
|
cloud.google.com/go/compute v1.12.1 // indirect
|
||||||
|
cloud.google.com/go/compute/metadata v0.2.1 // indirect
|
||||||
|
cloud.google.com/go/firestore v1.8.0 // indirect
|
||||||
|
cloud.google.com/go/longrunning v0.3.0 // indirect
|
||||||
|
github.com/Microsoft/go-winio v0.5.1 // indirect
|
||||||
|
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
|
||||||
|
github.com/acomagu/bufpipe v1.0.3 // indirect
|
||||||
|
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
|
||||||
|
github.com/armon/go-metrics v0.4.1 // indirect
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/bitly/go-simplejson v0.5.0 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
|
github.com/coreos/go-semver v0.3.0 // indirect
|
||||||
|
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
|
github.com/dtm-labs/dtmdriver v0.0.6 // indirect
|
||||||
|
github.com/dtm-labs/logger v0.0.1 // indirect
|
||||||
|
github.com/emirpasic/gods v1.12.0 // indirect
|
||||||
|
github.com/evanphx/json-patch/v5 v5.5.0 // indirect
|
||||||
|
github.com/fatih/color v1.13.0 // indirect
|
||||||
|
github.com/felixge/httpsnoop v1.0.2 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-acme/lego/v4 v4.4.0 // indirect
|
||||||
|
github.com/go-git/gcfg v1.5.0 // indirect
|
||||||
|
github.com/go-git/go-billy/v5 v5.3.1 // indirect
|
||||||
|
github.com/go-git/go-git/v5 v5.4.2 // indirect
|
||||||
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.11.0 // indirect
|
||||||
|
github.com/go-redis/redis/v8 v8.11.5 // indirect
|
||||||
|
github.com/go-resty/resty/v2 v2.7.0 // indirect
|
||||||
|
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||||
|
github.com/go-stack/stack v1.8.0 // indirect
|
||||||
|
github.com/gobwas/httphead v0.1.0 // indirect
|
||||||
|
github.com/gobwas/pool v0.2.1 // indirect
|
||||||
|
github.com/gobwas/ws v1.0.4 // indirect
|
||||||
|
github.com/goccy/go-json v0.9.7 // indirect
|
||||||
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
|
github.com/google/go-cmp v0.5.9 // indirect
|
||||||
|
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
|
||||||
|
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
|
||||||
|
github.com/gorilla/handlers v1.5.1 // indirect
|
||||||
|
github.com/hashicorp/consul/api v1.15.3 // indirect
|
||||||
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
|
github.com/hashicorp/go-hclog v1.3.1 // indirect
|
||||||
|
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
|
||||||
|
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||||
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
|
github.com/hashicorp/serf v0.10.1 // indirect
|
||||||
|
github.com/imdario/mergo v0.3.12 // indirect
|
||||||
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
||||||
|
github.com/klauspost/compress v1.14.4 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
|
github.com/mitchellh/hashstructure v1.1.0 // indirect
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
|
||||||
|
github.com/nxadm/tail v1.4.8 // indirect
|
||||||
|
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
|
||||||
|
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
|
||||||
|
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/prometheus/client_golang v1.14.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.3.0 // indirect
|
||||||
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
|
github.com/sagikazarmark/crypt v0.7.0 // indirect
|
||||||
|
github.com/sergi/go-diff v1.2.0 // indirect
|
||||||
|
github.com/spf13/afero v1.9.2 // indirect
|
||||||
|
github.com/spf13/cast v1.5.0 // indirect
|
||||||
|
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/spf13/viper v1.13.0 // indirect
|
||||||
|
github.com/subosito/gotenv v1.4.1 // indirect
|
||||||
|
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
|
||||||
|
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
|
||||||
|
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||||
|
github.com/urfave/cli/v2 v2.3.0 // indirect
|
||||||
|
github.com/xanzy/ssh-agent v0.3.0 // indirect
|
||||||
|
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||||
|
github.com/xdg-go/scram v1.0.2 // indirect
|
||||||
|
github.com/xdg-go/stringprep v1.0.2 // indirect
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||||
|
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
|
||||||
|
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
|
||||||
|
go.etcd.io/etcd/client/v2 v2.305.5 // indirect
|
||||||
|
go.etcd.io/etcd/client/v3 v3.5.5 // indirect
|
||||||
|
go.mongodb.org/mongo-driver v1.9.1 // indirect
|
||||||
|
go.opencensus.io v0.24.0 // indirect
|
||||||
|
go.uber.org/atomic v1.10.0 // indirect
|
||||||
|
go.uber.org/multierr v1.8.0 // indirect
|
||||||
|
go.uber.org/ratelimit v0.2.0 // indirect
|
||||||
|
go.uber.org/zap v1.23.0 // indirect
|
||||||
|
golang.org/x/crypto v0.1.0 // indirect
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||||
|
golang.org/x/oauth2 v0.1.0 // indirect
|
||||||
|
golang.org/x/text v0.4.0 // indirect
|
||||||
|
golang.org/x/time v0.1.0 // indirect
|
||||||
|
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||||
|
google.golang.org/api v0.102.0 // indirect
|
||||||
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
|
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
|
||||||
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||||
|
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gorm.io/driver/mysql v1.4.3 // indirect
|
||||||
|
)
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,37 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"trade-order/domain/service"
|
||||||
|
"trade-order/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TradeOrderHandler struct {
|
||||||
|
TradeOrderService service.ITradeOrderService
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增购物车
|
||||||
|
func (u *TradeOrderHandler) AddTradeOrder(ctx context.Context, req *proto.AddTradeOrderReq, resp *proto.AddTradeOrderResp) error {
|
||||||
|
obj, err := u.TradeOrderService.AddTradeOrder(req)
|
||||||
|
if err != nil {
|
||||||
|
println(" AddTradeOrder err :", err)
|
||||||
|
} else {
|
||||||
|
fmt.Println(obj.UpdateTime)
|
||||||
|
fmt.Println(" AddTradeOrder handler >>>>>> ", resp)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//修改购物车
|
||||||
|
|
||||||
|
func (u *TradeOrderHandler) UpdateTradeOrder(ctx context.Context, req *proto.AddTradeOrderReq, resp *proto.AddTradeOrderResp) error {
|
||||||
|
obj, err := u.TradeOrderService.UpdateTradeOrder(req)
|
||||||
|
if err != nil {
|
||||||
|
println(" UpdateTradeOrder err :", err)
|
||||||
|
} else {
|
||||||
|
fmt.Println(obj.UpdateTime)
|
||||||
|
fmt.Println(" UpdateTradeOrder handler >>>>>> ", resp)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "git.mashibing.com/msb_47094/shopping-comm"
|
||||||
|
consul "github.com/asim/go-micro/plugins/registry/consul/v4"
|
||||||
|
"github.com/go-micro/plugins/v4/wrapper/monitoring/prometheus"
|
||||||
|
ratelimiter "github.com/go-micro/plugins/v4/wrapper/ratelimiter/uber"
|
||||||
|
opentracing2 "github.com/go-micro/plugins/v4/wrapper/trace/opentracing"
|
||||||
|
"github.com/opentracing/opentracing-go"
|
||||||
|
"go-micro.dev/v4"
|
||||||
|
"go-micro.dev/v4/registry"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
"trade-order/domain/repository"
|
||||||
|
"trade-order/domain/service"
|
||||||
|
"trade-order/handler"
|
||||||
|
"trade-order/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
//0 配置中心
|
||||||
|
consulConfig, err := common.GetConsulConfig(common.ConsulStr, common.TradeFileKey)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println("consulConfig err :", err)
|
||||||
|
}
|
||||||
|
// 1.consul注册中心
|
||||||
|
consulReist := consul.NewRegistry(func(options *registry.Options) {
|
||||||
|
options.Addrs = []string{common.ConsulReistStr}
|
||||||
|
})
|
||||||
|
//链路追踪实列化 注意addr是 jaeper地址 端口号6831
|
||||||
|
t, io, err := common.NewTracer("trade-order", common.ConsulIp+":6831")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer io.Close()
|
||||||
|
//设置全局的Tracing
|
||||||
|
opentracing.SetGlobalTracer(t)
|
||||||
|
//开始监控prometheus 默认暴露9092
|
||||||
|
common.PrometheusBoot(9092)
|
||||||
|
repcService := micro.NewService(
|
||||||
|
micro.RegisterTTL(time.Second*30),
|
||||||
|
micro.RegisterInterval(time.Second*30),
|
||||||
|
micro.Name("trade-order"),
|
||||||
|
micro.Address(":8085"),
|
||||||
|
micro.Version("v1"),
|
||||||
|
micro.Registry(consulReist),
|
||||||
|
//链路追踪
|
||||||
|
micro.WrapHandler(opentracing2.NewHandlerWrapper(opentracing.GlobalTracer())),
|
||||||
|
//server 限流
|
||||||
|
micro.WrapHandler(ratelimiter.NewHandlerWrapper(common.QPS)),
|
||||||
|
//添加监控
|
||||||
|
micro.WrapHandler(prometheus.NewHandlerWrapper()),
|
||||||
|
)
|
||||||
|
//2.初始化db
|
||||||
|
db, _ := common.GetMysqlFromConsul(consulConfig)
|
||||||
|
//3.创建服务实例
|
||||||
|
tradeService := service.NewTradeOrderService(repository.NewTradeRepository(db))
|
||||||
|
//4.注册handler
|
||||||
|
proto.RegisterAddTradeOrderHandler(repcService.Server(), &handler.TradeOrderHandler{tradeService})
|
||||||
|
//4.注册handler
|
||||||
|
proto.RegisterUpdateTradeOrderHandler(repcService.Server(), &handler.TradeOrderHandler{tradeService})
|
||||||
|
//5.启动服务
|
||||||
|
if err := repcService.Run(); err != nil {
|
||||||
|
log.Println("start cart service err :", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,695 @@
|
|||||||
|
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||||
|
// source: trade.proto
|
||||||
|
|
||||||
|
package proto
|
||||||
|
|
||||||
|
import (
|
||||||
|
fmt "fmt"
|
||||||
|
proto "google.golang.org/protobuf/proto"
|
||||||
|
math "math"
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
api "go-micro.dev/v4/api"
|
||||||
|
client "go-micro.dev/v4/client"
|
||||||
|
server "go-micro.dev/v4/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ api.Endpoint
|
||||||
|
var _ context.Context
|
||||||
|
var _ client.Option
|
||||||
|
var _ server.Option
|
||||||
|
|
||||||
|
// Api Endpoints for AddTradeOrder service
|
||||||
|
|
||||||
|
func NewAddTradeOrderEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for AddTradeOrder service
|
||||||
|
|
||||||
|
type AddTradeOrderService interface {
|
||||||
|
// rpc 服务
|
||||||
|
AddTradeOrder(ctx context.Context, in *AddTradeOrderReq, opts ...client.CallOption) (*AddTradeOrderResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type addTradeOrderService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAddTradeOrderService(name string, c client.Client) AddTradeOrderService {
|
||||||
|
return &addTradeOrderService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *addTradeOrderService) AddTradeOrder(ctx context.Context, in *AddTradeOrderReq, opts ...client.CallOption) (*AddTradeOrderResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "AddTradeOrder.AddTradeOrder", in)
|
||||||
|
out := new(AddTradeOrderResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for AddTradeOrder service
|
||||||
|
|
||||||
|
type AddTradeOrderHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
AddTradeOrder(context.Context, *AddTradeOrderReq, *AddTradeOrderResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterAddTradeOrderHandler(s server.Server, hdlr AddTradeOrderHandler, opts ...server.HandlerOption) error {
|
||||||
|
type addTradeOrder interface {
|
||||||
|
AddTradeOrder(ctx context.Context, in *AddTradeOrderReq, out *AddTradeOrderResp) error
|
||||||
|
}
|
||||||
|
type AddTradeOrder struct {
|
||||||
|
addTradeOrder
|
||||||
|
}
|
||||||
|
h := &addTradeOrderHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&AddTradeOrder{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type addTradeOrderHandler struct {
|
||||||
|
AddTradeOrderHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *addTradeOrderHandler) AddTradeOrder(ctx context.Context, in *AddTradeOrderReq, out *AddTradeOrderResp) error {
|
||||||
|
return h.AddTradeOrderHandler.AddTradeOrder(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for UpdateTradeOrder service
|
||||||
|
|
||||||
|
func NewUpdateTradeOrderEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for UpdateTradeOrder service
|
||||||
|
|
||||||
|
type UpdateTradeOrderService interface {
|
||||||
|
// rpc 服务
|
||||||
|
UpdateTradeOrder(ctx context.Context, in *AddTradeOrderReq, opts ...client.CallOption) (*AddTradeOrderResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateTradeOrderService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdateTradeOrderService(name string, c client.Client) UpdateTradeOrderService {
|
||||||
|
return &updateTradeOrderService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *updateTradeOrderService) UpdateTradeOrder(ctx context.Context, in *AddTradeOrderReq, opts ...client.CallOption) (*AddTradeOrderResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "UpdateTradeOrder.UpdateTradeOrder", in)
|
||||||
|
out := new(AddTradeOrderResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for UpdateTradeOrder service
|
||||||
|
|
||||||
|
type UpdateTradeOrderHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
UpdateTradeOrder(context.Context, *AddTradeOrderReq, *AddTradeOrderResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterUpdateTradeOrderHandler(s server.Server, hdlr UpdateTradeOrderHandler, opts ...server.HandlerOption) error {
|
||||||
|
type updateTradeOrder interface {
|
||||||
|
UpdateTradeOrder(ctx context.Context, in *AddTradeOrderReq, out *AddTradeOrderResp) error
|
||||||
|
}
|
||||||
|
type UpdateTradeOrder struct {
|
||||||
|
updateTradeOrder
|
||||||
|
}
|
||||||
|
h := &updateTradeOrderHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&UpdateTradeOrder{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateTradeOrderHandler struct {
|
||||||
|
UpdateTradeOrderHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *updateTradeOrderHandler) UpdateTradeOrder(ctx context.Context, in *AddTradeOrderReq, out *AddTradeOrderResp) error {
|
||||||
|
return h.UpdateTradeOrderHandler.UpdateTradeOrder(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for UpdateCart service
|
||||||
|
|
||||||
|
func NewUpdateCartEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for UpdateCart service
|
||||||
|
|
||||||
|
type UpdateCartService interface {
|
||||||
|
// rpc 服务
|
||||||
|
UpdateCart(ctx context.Context, in *UpdateCartReq, opts ...client.CallOption) (*UpdateCartResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateCartService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdateCartService(name string, c client.Client) UpdateCartService {
|
||||||
|
return &updateCartService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *updateCartService) UpdateCart(ctx context.Context, in *UpdateCartReq, opts ...client.CallOption) (*UpdateCartResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "UpdateCart.UpdateCart", in)
|
||||||
|
out := new(UpdateCartResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for UpdateCart service
|
||||||
|
|
||||||
|
type UpdateCartHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
UpdateCart(context.Context, *UpdateCartReq, *UpdateCartResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterUpdateCartHandler(s server.Server, hdlr UpdateCartHandler, opts ...server.HandlerOption) error {
|
||||||
|
type updateCart interface {
|
||||||
|
UpdateCart(ctx context.Context, in *UpdateCartReq, out *UpdateCartResp) error
|
||||||
|
}
|
||||||
|
type UpdateCart struct {
|
||||||
|
updateCart
|
||||||
|
}
|
||||||
|
h := &updateCartHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&UpdateCart{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateCartHandler struct {
|
||||||
|
UpdateCartHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *updateCartHandler) UpdateCart(ctx context.Context, in *UpdateCartReq, out *UpdateCartResp) error {
|
||||||
|
return h.UpdateCartHandler.UpdateCart(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for FindCart service
|
||||||
|
|
||||||
|
func NewFindCartEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for FindCart service
|
||||||
|
|
||||||
|
type FindCartService interface {
|
||||||
|
FindCart(ctx context.Context, in *FindCartReq, opts ...client.CallOption) (*FindCartResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type findCartService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFindCartService(name string, c client.Client) FindCartService {
|
||||||
|
return &findCartService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *findCartService) FindCart(ctx context.Context, in *FindCartReq, opts ...client.CallOption) (*FindCartResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "FindCart.FindCart", in)
|
||||||
|
out := new(FindCartResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for FindCart service
|
||||||
|
|
||||||
|
type FindCartHandler interface {
|
||||||
|
FindCart(context.Context, *FindCartReq, *FindCartResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterFindCartHandler(s server.Server, hdlr FindCartHandler, opts ...server.HandlerOption) error {
|
||||||
|
type findCart interface {
|
||||||
|
FindCart(ctx context.Context, in *FindCartReq, out *FindCartResp) error
|
||||||
|
}
|
||||||
|
type FindCart struct {
|
||||||
|
findCart
|
||||||
|
}
|
||||||
|
h := &findCartHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&FindCart{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type findCartHandler struct {
|
||||||
|
FindCartHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *findCartHandler) FindCart(ctx context.Context, in *FindCartReq, out *FindCartResp) error {
|
||||||
|
return h.FindCartHandler.FindCart(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for Page service
|
||||||
|
|
||||||
|
func NewPageEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for Page service
|
||||||
|
|
||||||
|
type PageService interface {
|
||||||
|
// rpc 服务
|
||||||
|
Page(ctx context.Context, in *PageReq, opts ...client.CallOption) (*PageResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type pageService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPageService(name string, c client.Client) PageService {
|
||||||
|
return &pageService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *pageService) Page(ctx context.Context, in *PageReq, opts ...client.CallOption) (*PageResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "Page.Page", in)
|
||||||
|
out := new(PageResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for Page service
|
||||||
|
|
||||||
|
type PageHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
Page(context.Context, *PageReq, *PageResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterPageHandler(s server.Server, hdlr PageHandler, opts ...server.HandlerOption) error {
|
||||||
|
type page interface {
|
||||||
|
Page(ctx context.Context, in *PageReq, out *PageResp) error
|
||||||
|
}
|
||||||
|
type Page struct {
|
||||||
|
page
|
||||||
|
}
|
||||||
|
h := &pageHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&Page{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type pageHandler struct {
|
||||||
|
PageHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *pageHandler) Page(ctx context.Context, in *PageReq, out *PageResp) error {
|
||||||
|
return h.PageHandler.Page(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for ShowProductDetail service
|
||||||
|
|
||||||
|
func NewShowProductDetailEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for ShowProductDetail service
|
||||||
|
|
||||||
|
type ShowProductDetailService interface {
|
||||||
|
// rpc 服务
|
||||||
|
ShowProductDetail(ctx context.Context, in *ProductDetailReq, opts ...client.CallOption) (*ProductDetailResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type showProductDetailService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewShowProductDetailService(name string, c client.Client) ShowProductDetailService {
|
||||||
|
return &showProductDetailService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *showProductDetailService) ShowProductDetail(ctx context.Context, in *ProductDetailReq, opts ...client.CallOption) (*ProductDetailResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "ShowProductDetail.ShowProductDetail", in)
|
||||||
|
out := new(ProductDetailResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for ShowProductDetail service
|
||||||
|
|
||||||
|
type ShowProductDetailHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
ShowProductDetail(context.Context, *ProductDetailReq, *ProductDetailResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterShowProductDetailHandler(s server.Server, hdlr ShowProductDetailHandler, opts ...server.HandlerOption) error {
|
||||||
|
type showProductDetail interface {
|
||||||
|
ShowProductDetail(ctx context.Context, in *ProductDetailReq, out *ProductDetailResp) error
|
||||||
|
}
|
||||||
|
type ShowProductDetail struct {
|
||||||
|
showProductDetail
|
||||||
|
}
|
||||||
|
h := &showProductDetailHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&ShowProductDetail{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type showProductDetailHandler struct {
|
||||||
|
ShowProductDetailHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *showProductDetailHandler) ShowProductDetail(ctx context.Context, in *ProductDetailReq, out *ProductDetailResp) error {
|
||||||
|
return h.ShowProductDetailHandler.ShowProductDetail(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for ShowProductSku service
|
||||||
|
|
||||||
|
func NewShowProductSkuEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for ShowProductSku service
|
||||||
|
|
||||||
|
type ShowProductSkuService interface {
|
||||||
|
// rpc 服务
|
||||||
|
ShowProductSku(ctx context.Context, in *ProductSkuReq, opts ...client.CallOption) (*ProductSkuResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type showProductSkuService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewShowProductSkuService(name string, c client.Client) ShowProductSkuService {
|
||||||
|
return &showProductSkuService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *showProductSkuService) ShowProductSku(ctx context.Context, in *ProductSkuReq, opts ...client.CallOption) (*ProductSkuResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "ShowProductSku.ShowProductSku", in)
|
||||||
|
out := new(ProductSkuResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for ShowProductSku service
|
||||||
|
|
||||||
|
type ShowProductSkuHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
ShowProductSku(context.Context, *ProductSkuReq, *ProductSkuResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterShowProductSkuHandler(s server.Server, hdlr ShowProductSkuHandler, opts ...server.HandlerOption) error {
|
||||||
|
type showProductSku interface {
|
||||||
|
ShowProductSku(ctx context.Context, in *ProductSkuReq, out *ProductSkuResp) error
|
||||||
|
}
|
||||||
|
type ShowProductSku struct {
|
||||||
|
showProductSku
|
||||||
|
}
|
||||||
|
h := &showProductSkuHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&ShowProductSku{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type showProductSkuHandler struct {
|
||||||
|
ShowProductSkuHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *showProductSkuHandler) ShowProductSku(ctx context.Context, in *ProductSkuReq, out *ProductSkuResp) error {
|
||||||
|
return h.ShowProductSkuHandler.ShowProductSku(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for ShowDetailSku service
|
||||||
|
|
||||||
|
func NewShowDetailSkuEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for ShowDetailSku service
|
||||||
|
|
||||||
|
type ShowDetailSkuService interface {
|
||||||
|
// rpc 服务
|
||||||
|
ShowDetailSku(ctx context.Context, in *ProductDetailReq, opts ...client.CallOption) (*ProductSkuResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type showDetailSkuService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewShowDetailSkuService(name string, c client.Client) ShowDetailSkuService {
|
||||||
|
return &showDetailSkuService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *showDetailSkuService) ShowDetailSku(ctx context.Context, in *ProductDetailReq, opts ...client.CallOption) (*ProductSkuResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "ShowDetailSku.ShowDetailSku", in)
|
||||||
|
out := new(ProductSkuResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for ShowDetailSku service
|
||||||
|
|
||||||
|
type ShowDetailSkuHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
ShowDetailSku(context.Context, *ProductDetailReq, *ProductSkuResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterShowDetailSkuHandler(s server.Server, hdlr ShowDetailSkuHandler, opts ...server.HandlerOption) error {
|
||||||
|
type showDetailSku interface {
|
||||||
|
ShowDetailSku(ctx context.Context, in *ProductDetailReq, out *ProductSkuResp) error
|
||||||
|
}
|
||||||
|
type ShowDetailSku struct {
|
||||||
|
showDetailSku
|
||||||
|
}
|
||||||
|
h := &showDetailSkuHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&ShowDetailSku{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type showDetailSkuHandler struct {
|
||||||
|
ShowDetailSkuHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *showDetailSkuHandler) ShowDetailSku(ctx context.Context, in *ProductDetailReq, out *ProductSkuResp) error {
|
||||||
|
return h.ShowDetailSkuHandler.ShowDetailSku(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for GetUserToken service
|
||||||
|
|
||||||
|
func NewGetUserTokenEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for GetUserToken service
|
||||||
|
|
||||||
|
type GetUserTokenService interface {
|
||||||
|
// rpc 服务
|
||||||
|
GetUserToken(ctx context.Context, in *TokenReq, opts ...client.CallOption) (*TokenResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type getUserTokenService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetUserTokenService(name string, c client.Client) GetUserTokenService {
|
||||||
|
return &getUserTokenService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *getUserTokenService) GetUserToken(ctx context.Context, in *TokenReq, opts ...client.CallOption) (*TokenResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "GetUserToken.GetUserToken", in)
|
||||||
|
out := new(TokenResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for GetUserToken service
|
||||||
|
|
||||||
|
type GetUserTokenHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
GetUserToken(context.Context, *TokenReq, *TokenResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterGetUserTokenHandler(s server.Server, hdlr GetUserTokenHandler, opts ...server.HandlerOption) error {
|
||||||
|
type getUserToken interface {
|
||||||
|
GetUserToken(ctx context.Context, in *TokenReq, out *TokenResp) error
|
||||||
|
}
|
||||||
|
type GetUserToken struct {
|
||||||
|
getUserToken
|
||||||
|
}
|
||||||
|
h := &getUserTokenHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&GetUserToken{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type getUserTokenHandler struct {
|
||||||
|
GetUserTokenHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *getUserTokenHandler) GetUserToken(ctx context.Context, in *TokenReq, out *TokenResp) error {
|
||||||
|
return h.GetUserTokenHandler.GetUserToken(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for UpdateSku service
|
||||||
|
|
||||||
|
func NewUpdateSkuEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for UpdateSku service
|
||||||
|
|
||||||
|
type UpdateSkuService interface {
|
||||||
|
UpdateSku(ctx context.Context, in *UpdateSkuReq, opts ...client.CallOption) (*UpdateSkuResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateSkuService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdateSkuService(name string, c client.Client) UpdateSkuService {
|
||||||
|
return &updateSkuService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *updateSkuService) UpdateSku(ctx context.Context, in *UpdateSkuReq, opts ...client.CallOption) (*UpdateSkuResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "UpdateSku.UpdateSku", in)
|
||||||
|
out := new(UpdateSkuResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for UpdateSku service
|
||||||
|
|
||||||
|
type UpdateSkuHandler interface {
|
||||||
|
UpdateSku(context.Context, *UpdateSkuReq, *UpdateSkuResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterUpdateSkuHandler(s server.Server, hdlr UpdateSkuHandler, opts ...server.HandlerOption) error {
|
||||||
|
type updateSku interface {
|
||||||
|
UpdateSku(ctx context.Context, in *UpdateSkuReq, out *UpdateSkuResp) error
|
||||||
|
}
|
||||||
|
type UpdateSku struct {
|
||||||
|
updateSku
|
||||||
|
}
|
||||||
|
h := &updateSkuHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&UpdateSku{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateSkuHandler struct {
|
||||||
|
UpdateSkuHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *updateSkuHandler) UpdateSku(ctx context.Context, in *UpdateSkuReq, out *UpdateSkuResp) error {
|
||||||
|
return h.UpdateSkuHandler.UpdateSku(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api Endpoints for GetOrderTotal service
|
||||||
|
|
||||||
|
func NewGetOrderTotalEndpoints() []*api.Endpoint {
|
||||||
|
return []*api.Endpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for GetOrderTotal service
|
||||||
|
|
||||||
|
type GetOrderTotalService interface {
|
||||||
|
// rpc 服务
|
||||||
|
GetOrderTotal(ctx context.Context, in *OrderTotalReq, opts ...client.CallOption) (*OrderTotalResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type getOrderTotalService struct {
|
||||||
|
c client.Client
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetOrderTotalService(name string, c client.Client) GetOrderTotalService {
|
||||||
|
return &getOrderTotalService{
|
||||||
|
c: c,
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *getOrderTotalService) GetOrderTotal(ctx context.Context, in *OrderTotalReq, opts ...client.CallOption) (*OrderTotalResp, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "GetOrderTotal.GetOrderTotal", in)
|
||||||
|
out := new(OrderTotalResp)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for GetOrderTotal service
|
||||||
|
|
||||||
|
type GetOrderTotalHandler interface {
|
||||||
|
// rpc 服务
|
||||||
|
GetOrderTotal(context.Context, *OrderTotalReq, *OrderTotalResp) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterGetOrderTotalHandler(s server.Server, hdlr GetOrderTotalHandler, opts ...server.HandlerOption) error {
|
||||||
|
type getOrderTotal interface {
|
||||||
|
GetOrderTotal(ctx context.Context, in *OrderTotalReq, out *OrderTotalResp) error
|
||||||
|
}
|
||||||
|
type GetOrderTotal struct {
|
||||||
|
getOrderTotal
|
||||||
|
}
|
||||||
|
h := &getOrderTotalHandler{hdlr}
|
||||||
|
return s.Handle(s.NewHandler(&GetOrderTotal{h}, opts...))
|
||||||
|
}
|
||||||
|
|
||||||
|
type getOrderTotalHandler struct {
|
||||||
|
GetOrderTotalHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *getOrderTotalHandler) GetOrderTotal(ctx context.Context, in *OrderTotalReq, out *OrderTotalResp) error {
|
||||||
|
return h.GetOrderTotalHandler.GetOrderTotal(ctx, in, out)
|
||||||
|
}
|
@ -1,107 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
_ "github.com/spf13/viper/remote"
|
|
||||||
"gorm.io/driver/mysql"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/logger"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetConsulConfig(url string, fileKey string) (*viper.Viper, error) {
|
|
||||||
conf := viper.New()
|
|
||||||
conf.AddRemoteProvider("consul", url, fileKey)
|
|
||||||
conf.SetConfigType("json")
|
|
||||||
err := conf.ReadRemoteConfig()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("viper conf err :", err)
|
|
||||||
//}else {
|
|
||||||
//log.Println("viper conf :", conf)
|
|
||||||
}
|
|
||||||
return conf, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
{
|
|
||||||
"host": "192.168.137.131",
|
|
||||||
"port": "3306",
|
|
||||||
"user": "root",
|
|
||||||
"pwd": "mashibing123",
|
|
||||||
"database": "user_center"
|
|
||||||
}
|
|
||||||
**/
|
|
||||||
|
|
||||||
// type MySQLConfig struct {
|
|
||||||
// Host string `json:"host"`
|
|
||||||
// Post string `json:"port"`
|
|
||||||
// User string `json:"user"`
|
|
||||||
// Pwd string `json:"pwd"`
|
|
||||||
// Database string `json:"database"`
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// 获取 MySQL配置
|
|
||||||
func GetMysqlFromConsul(vip *viper.Viper) (db *gorm.DB, err error) {
|
|
||||||
newLogger := logger.New(
|
|
||||||
log.New(os.Stdout, "\r\n", log.LstdFlags),
|
|
||||||
logger.Config{
|
|
||||||
SlowThreshold: time.Second,
|
|
||||||
LogLevel: logger.Info,
|
|
||||||
Colorful: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
str := vip.GetString("user") + ":" + vip.GetString("pwd") + "@tcp(" + vip.GetString("host") + ":" + vip.GetString("port") + ")/" + vip.GetString("database") + "?charset=utf8mb4&parseTime=True&loc=Local"
|
|
||||||
db, errr := gorm.Open(mysql.Open(str), &gorm.Config{Logger: newLogger}) //"root:mashibing123@tcp(8.142.25.43:3306)/user_center?charset=utf8mb4&parseTime=True&loc=Local"), &gorm.Config{Logger: newLogger})
|
|
||||||
if errr != nil {
|
|
||||||
log.Println("db err :", errr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return db, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
{
|
|
||||||
"addr": "192.168.100.131",
|
|
||||||
"password": "",
|
|
||||||
"DB": "0",
|
|
||||||
"poolSize": "30",
|
|
||||||
"minIdleConn": "30"
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// 获取redis 配置
|
|
||||||
func GetRedisFromConsul(vip *viper.Viper) (red *redis.Client, err error) {
|
|
||||||
red = redis.NewClient(&redis.Options{
|
|
||||||
Addr: vip.GetString("addr"),
|
|
||||||
Password: vip.GetString("password"),
|
|
||||||
DB: vip.GetInt("DB"),
|
|
||||||
PoolSize: vip.GetInt("poolSize"),
|
|
||||||
MinIdleConns: vip.GetInt("minIdleConn"),
|
|
||||||
})
|
|
||||||
//集群
|
|
||||||
clusterClients := redis.NewClusterClient(
|
|
||||||
&redis.ClusterOptions{
|
|
||||||
Addrs: []string{"192.168.100.131:6380", "192.168.100.131:6381", "192.168.100.131:6382"},
|
|
||||||
})
|
|
||||||
fmt.Println(clusterClients)
|
|
||||||
return red, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置用户登录信息
|
|
||||||
func SetUserToken(red *redis.Client, key string, val []byte, timeTTL time.Duration) {
|
|
||||||
red.Set(context.Background(), key, val, timeTTL)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取用户登录信息
|
|
||||||
func GetUserToken(red *redis.Client, key string) string {
|
|
||||||
res, err := red.Get(context.Background(), key).Result()
|
|
||||||
if err != nil {
|
|
||||||
log.Print("GetUserToken err ", err)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
//小写
|
|
||||||
func Md5Encode(data string) string {
|
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(data))
|
|
||||||
tempStr := h.Sum(nil)
|
|
||||||
return hex.EncodeToString(tempStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
//大写
|
|
||||||
func MD5Encode(data string) string {
|
|
||||||
return strings.ToUpper(Md5Encode(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
//加密
|
|
||||||
func MakePassword(plainpwd, salt string) string {
|
|
||||||
return Md5Encode(plainpwd + salt)
|
|
||||||
}
|
|
||||||
|
|
||||||
//解密
|
|
||||||
func ValidPassword(plainpwd, salt string, password string) bool {
|
|
||||||
md := Md5Encode(plainpwd + salt)
|
|
||||||
fmt.Println(md + " " + password)
|
|
||||||
return md == password
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
type H struct {
|
|
||||||
Code string
|
|
||||||
Message string
|
|
||||||
TraceId string
|
|
||||||
Data interface{}
|
|
||||||
Rows interface{}
|
|
||||||
Total interface{}
|
|
||||||
SkyWalkingDynamicField string
|
|
||||||
}
|
|
||||||
|
|
||||||
func Resp(w http.ResponseWriter, code string, data interface{}, message string) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
h := H{
|
|
||||||
Code: code,
|
|
||||||
Data: data,
|
|
||||||
Message: message,
|
|
||||||
}
|
|
||||||
ret, err := json.Marshal(h)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
w.Write(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RespList(w http.ResponseWriter, code string, data interface{}, message string, rows interface{}, total interface{}, skyWalkingDynamicField string) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
h := H{
|
|
||||||
Code: code,
|
|
||||||
Data: data,
|
|
||||||
Message: message,
|
|
||||||
Rows: rows,
|
|
||||||
Total: total,
|
|
||||||
SkyWalkingDynamicField: skyWalkingDynamicField,
|
|
||||||
}
|
|
||||||
ret, err := json.Marshal(h)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
w.Write(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
200 OKLoginSuccessVO
|
|
||||||
201 Created
|
|
||||||
401 Unauthorized
|
|
||||||
403 Forbidden
|
|
||||||
404 Not Found
|
|
||||||
**/
|
|
||||||
func RespOK(w http.ResponseWriter, data interface{}, message string) {
|
|
||||||
Resp(w, "SUCCESS", data, message)
|
|
||||||
}
|
|
||||||
func RespFail(w http.ResponseWriter, data interface{}, message string) {
|
|
||||||
Resp(w, "TOKEN_FAIL", data, message)
|
|
||||||
}
|
|
||||||
func RespListOK(w http.ResponseWriter, data interface{}, message string, rows interface{}, total interface{}, skyWalkingDynamicField string) {
|
|
||||||
RespList(w, "SUCCESS", data, message, rows, total, skyWalkingDynamicField)
|
|
||||||
}
|
|
||||||
func RespListFail(w http.ResponseWriter, data interface{}, message string, rows interface{}, total interface{}, skyWalkingDynamicField string) {
|
|
||||||
RespList(w, "TOKEN_FAIL", data, message, rows, total, skyWalkingDynamicField)
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
@Auth:ShenZ
|
|
||||||
@Description: 用于UUID 加密算法
|
|
||||||
*/
|
|
||||||
|
|
||||||
func StringToArray(intput string) []int {
|
|
||||||
output := []int{}
|
|
||||||
for _, v := range intput {
|
|
||||||
output = append(output, int(v))
|
|
||||||
}
|
|
||||||
for i, j := 0, len(output)-1; i < j; i, j = i+1, j-1 {
|
|
||||||
output[i], output[j] = output[j], output[i]
|
|
||||||
}
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
func GetInput(intput string) <-chan int {
|
|
||||||
out := make(chan int)
|
|
||||||
go func() {
|
|
||||||
for _, b := range StringToArray(intput) {
|
|
||||||
out <- b
|
|
||||||
}
|
|
||||||
close(out)
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
func SQ(in <-chan int) <-chan int {
|
|
||||||
out := make(chan int)
|
|
||||||
var base, i float64 = 2, 0
|
|
||||||
go func() {
|
|
||||||
for n := range in {
|
|
||||||
out <- (n - 48) * int(math.Pow(base, i))
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
close(out)
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func ToInt(intput string) int {
|
|
||||||
//intput := "101010101110110"
|
|
||||||
c := GetInput(intput)
|
|
||||||
out := SQ(c)
|
|
||||||
sum := 0
|
|
||||||
for o := range out {
|
|
||||||
sum += o
|
|
||||||
}
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
||||||
// int 转 二进制的字符串
|
|
||||||
func ConverToBinary(n int) string {
|
|
||||||
res := ""
|
|
||||||
for ; n > 0; n /= 2 {
|
|
||||||
lsb := n % 2
|
|
||||||
res = strconv.Itoa(lsb) + res
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
Loading…
Reference in new issue