From c0cdae1240ea7d0fc3161559ed9d3efcc26fe6a7 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 15 Aug 2022 11:51:07 +0700 Subject: [PATCH] define global care api --- .gitignore | 1 + constant/natsio.go | 9 ++ go.mod | 38 ++++++ go.sum | 161 ++++++++++++++++++++++++ model/natsio/communication_request.go | 17 +++ model/natsio/communication_response.go | 17 +++ partnerapi/globalcare/const.go | 38 ++++++ partnerapi/globalcare/env.go | 10 ++ partnerapi/globalcare/globale_care.go | 128 +++++++++++++++++++ partnerapi/globalcare/model_request.go | 43 +++++++ partnerapi/globalcare/model_response.go | 8 ++ partnerapi/globalcare/nats.go | 1 + partnerapi/globalcare/util.go | 45 +++++++ util/base64/base64.go | 15 +++ util/pjson/bytes.go | 16 +++ util/pjson/string.go | 6 + util/pjson/unmarshal.go | 19 +++ 17 files changed, 572 insertions(+) create mode 100644 constant/natsio.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 model/natsio/communication_request.go create mode 100644 model/natsio/communication_response.go create mode 100644 partnerapi/globalcare/const.go create mode 100644 partnerapi/globalcare/env.go create mode 100644 partnerapi/globalcare/globale_care.go create mode 100644 partnerapi/globalcare/model_request.go create mode 100644 partnerapi/globalcare/model_response.go create mode 100644 partnerapi/globalcare/nats.go create mode 100644 partnerapi/globalcare/util.go create mode 100644 util/base64/base64.go create mode 100644 util/pjson/bytes.go create mode 100644 util/pjson/string.go create mode 100644 util/pjson/unmarshal.go diff --git a/.gitignore b/.gitignore index 66fd13c..d1baad6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ # Dependency directories (remove the comment below to include it) # vendor/ +.idea \ No newline at end of file diff --git a/constant/natsio.go b/constant/natsio.go new file mode 100644 index 0000000..d730e74 --- /dev/null +++ b/constant/natsio.go @@ -0,0 +1,9 @@ +package constant + +const natsCommunicationPrefix = "communication_" + +const ( + NatsCommunicationSubjectRequestHTTP = natsCommunicationPrefix + "request_http" + NatsCommunicationSubjectResponseHTTP = natsCommunicationPrefix + "response_http" + NatsCommunicationSubjectWebhookTNC = natsCommunicationPrefix + "webhook_tnc" +) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..299b4e2 --- /dev/null +++ b/go.mod @@ -0,0 +1,38 @@ +module github.com/Selly-Modules/tpl + +go 1.17 + +require ( + github.com/Selly-Modules/logger v0.0.1 + github.com/Selly-Modules/natsio v1.0.0 +) + +require ( + github.com/armon/go-radix v1.0.0 // indirect + github.com/elastic/go-licenser v0.3.1 // indirect + github.com/elastic/go-sysinfo v1.1.1 // indirect + github.com/elastic/go-windows v1.0.0 // indirect + github.com/jcchavezs/porto v0.1.0 // indirect + github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect + github.com/logrusorgru/aurora v2.0.3+incompatible // indirect + github.com/nats-io/nats.go v1.13.0 // indirect + github.com/nats-io/nkeys v0.3.0 // indirect + github.com/nats-io/nuid v1.0.1 // indirect + github.com/pkg/errors v0.8.1 // indirect + github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 // indirect + github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect + github.com/thoas/go-funk v0.9.1 // indirect + go.elastic.co/apm v1.13.1 // indirect + go.elastic.co/apm/module/apmzap v1.13.1 // indirect + go.elastic.co/fastjson v1.1.0 // indirect + go.uber.org/atomic v1.7.0 // indirect + go.uber.org/multierr v1.6.0 // indirect + go.uber.org/zap v1.18.1 // indirect + golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect + golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect + golang.org/x/mod v0.3.0 // indirect + golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect + golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5 // indirect + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect + howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..318d807 --- /dev/null +++ b/go.sum @@ -0,0 +1,161 @@ +github.com/Selly-Modules/logger v0.0.1 h1:dwLLtW53FfVBlklhdtFRB63eP0ofIh0IUQ/Gjgi0r5k= +github.com/Selly-Modules/logger v0.0.1/go.mod h1:RWhSQ3F01an8KD00VjzRBZOMcE5eV2Cy0/l4ZkeieyU= +github.com/Selly-Modules/natsio v1.0.0 h1:2GHm7upYn0CmqKPwfg2AXNmaAHuL7V9l36M4BgOmQ4M= +github.com/Selly-Modules/natsio v1.0.0/go.mod h1:NG55g9ip18nvN5tfP6PcSEKec10/lOeIOZC8HqBVNlQ= +github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +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/elastic/go-licenser v0.3.1 h1:RmRukU/JUmts+rpexAw0Fvt2ly7VVu6mw8z4HrEzObU= +github.com/elastic/go-licenser v0.3.1/go.mod h1:D8eNQk70FOCVBl3smCGQt/lv7meBeQno2eI1S5apiHQ= +github.com/elastic/go-sysinfo v1.1.1 h1:ZVlaLDyhVkDfjwPGU55CQRCRolNpc7P0BbyhhQZQmMI= +github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0= +github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7aSY= +github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +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/jcchavezs/porto v0.1.0 h1:Xmxxn25zQMmgE7/yHYmh19KcItG81hIwfbEEFnd6w/Q= +github.com/jcchavezs/porto v0.1.0/go.mod h1:fESH0gzDHiutHRdX2hv27ojnOVFco37hg1W6E9EZF4A= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= +github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s= +github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +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/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= +github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= +github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= +github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= +github.com/nats-io/jwt v1.2.2 h1:w3GMTO969dFg+UOKTmmyuu7IGdusK+7Ytlt//OYH/uU= +github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q= +github.com/nats-io/jwt/v2 v2.0.3 h1:i/O6cmIsjpcQyWDYNcq2JyZ3/VTF8SJ4JWluI5OhpvI= +github.com/nats-io/jwt/v2 v2.0.3/go.mod h1:VRP+deawSXyhNjXmxPCHskrR6Mq50BqpEI5SEcNiGlY= +github.com/nats-io/nats-server/v2 v2.6.1 h1:cJy+ia7/4EaJL+ZYDmIy2rD1mDWTfckhtPBU0GYo8xM= +github.com/nats-io/nats-server/v2 v2.6.1/go.mod h1:Az91TbZiV7K4a6k/4v6YYdOKEoxCXj+iqhHVf/MlrKo= +github.com/nats-io/nats.go v1.12.3/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= +github.com/nats-io/nats.go v1.13.0 h1:LvYqRB5epIzZWQp6lmeltOOZNLqCvm4b+qfvzZO03HE= +github.com/nats-io/nats.go v1.13.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= +github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= +github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= +github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= +github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= +github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +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/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 h1:c8R11WC8m7KNMkTv/0+Be8vvwo4I3/Ut9AC2FW8fX3U= +github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= +github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= +github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.elastic.co/apm v1.13.1 h1:ICIcUcQOImg/bve9mQVyLCvm1cSUZ1afdwK6ACnxczU= +go.elastic.co/apm v1.13.1/go.mod h1:dylGv2HKR0tiCV+wliJz1KHtDyuD8SPe69oV7VyK6WY= +go.elastic.co/apm/module/apmzap v1.13.1 h1:Soa4vNYYabPvOW1vm1A00C0UcEmfEzcx3YBjAgf5ue4= +go.elastic.co/apm/module/apmzap v1.13.1/go.mod h1:Tu8/TwffpBoNGmI05VcL1Ye2AC8oXrlMKNaKD1TIQy0= +go.elastic.co/fastjson v1.1.0 h1:3MrGBWWVIxe/xvsbpghtkFoPciPhOCmjsR/HfwEeQR4= +go.elastic.co/fastjson v1.1.0/go.mod h1:boNGISWMjQsUPy/t6yqt2/1Wx4YNPSe+mZjlyw9vKKI= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= +go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.18.1 h1:CSUJ2mjFszzEWt4CdKISEuChVIXGBn3lAPwkRGyVrc4= +go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +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-20191025021431-6c3a3bfe00ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/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.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= +golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5 h1:MeC2gMlMdkd67dn17MEby3rGXRxZtWeiRXOnISfTQ74= +golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +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/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M= +howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= diff --git a/model/natsio/communication_request.go b/model/natsio/communication_request.go new file mode 100644 index 0000000..ad1b55c --- /dev/null +++ b/model/natsio/communication_request.go @@ -0,0 +1,17 @@ +package natsiomodel + +// NatsRequestHTTP ... +type NatsRequestHTTP struct { + ResponseImmediately bool `json:"responseImmediately"` + AuthenticationID string `json:"authenticationId"` + Payload HTTPPayload `json:"payload"` +} + +// HTTPPayload ... +type HTTPPayload struct { + URL string `json:"url"` + Method string `json:"method"` + Data string `json:"data"` + Header map[string]string `json:"header"` + Query map[string]string `json:"query"` +} diff --git a/model/natsio/communication_response.go b/model/natsio/communication_response.go new file mode 100644 index 0000000..eb52be1 --- /dev/null +++ b/model/natsio/communication_response.go @@ -0,0 +1,17 @@ +package natsiomodel + +import "github.com/Selly-Modules/tpl/util/pjson" + +// NatsResponse ... +type NatsResponse struct { + Data interface{} `json:"data"` + Error bool `json:"error"` + Message string `json:"message"` + RequestID string `json:"requestId"` +} + +// ParseData ... +func (r *NatsResponse) ParseData(result interface{}) error { + b := pjson.ToBytes(r.Data) + return pjson.Unmarshal(b, result) +} diff --git a/partnerapi/globalcare/const.go b/partnerapi/globalcare/const.go new file mode 100644 index 0000000..00d6aeb --- /dev/null +++ b/partnerapi/globalcare/const.go @@ -0,0 +1,38 @@ +package globalcare + +const ( + baseURLDev = "https://core-dev.globalcare.vn" + baseURLStaging = "https://core-beta.globalcare.vn" + baseURLProd = "https://core.globalcare.vn" +) + +var ( + baseURLENVMapping = map[ENV]string{ + EnvProd: baseURLProd, + EnvStaging: baseURLStaging, + EnvDev: baseURLDev, + } +) + +const ( + apiPathCreateOrder = "/api/v1/partner/selly/order/create" + apiPathGetOrder = "/api/v1/partner/selly/order/%s/detail" +) + +const ( + VehicleTypeID50ccAbove = 1 + VehicleTypeID50ccBelow = 2 + VehicleTypeIDElectricBike = 3 +) + +const ( + CarOccupantAccidentInsurance0 = 1 + CarOccupantAccidentInsurance10m = 2 + CarOccupantAccidentInsurance20m = 3 +) + +const ( + productCodeDefault = "bbxm" + providerIDDefault = 4 + productIDDefault = 18 +) diff --git a/partnerapi/globalcare/env.go b/partnerapi/globalcare/env.go new file mode 100644 index 0000000..a713bdd --- /dev/null +++ b/partnerapi/globalcare/env.go @@ -0,0 +1,10 @@ +package globalcare + +// ENV ... +type ENV string + +const ( + EnvDev ENV = "DEV" + EnvStaging ENV = "STAGING" + EnvProd ENV = "PROD" +) diff --git a/partnerapi/globalcare/globale_care.go b/partnerapi/globalcare/globale_care.go new file mode 100644 index 0000000..76de1cc --- /dev/null +++ b/partnerapi/globalcare/globale_care.go @@ -0,0 +1,128 @@ +package globalcare + +import ( + "crypto/rsa" + "fmt" + "net/http" + + "github.com/Selly-Modules/logger" + "github.com/Selly-Modules/natsio" + "github.com/nats-io/nats.go" + "github.com/thoas/go-funk" + + "github.com/Selly-Modules/tpl/constant" + natsiomodel "github.com/Selly-Modules/tpl/model/natsio" + "github.com/Selly-Modules/tpl/util/base64" + "github.com/Selly-Modules/tpl/util/pjson" +) + +// Client ... +type Client struct { + privateKey *rsa.PrivateKey + publicKey *rsa.PublicKey + env ENV + natsClient natsio.Server +} + +// NewClient generate Client +// using privateKey to decrypt data from Global Care +// using publicKey to encrypt data before send to Global Care +func NewClient(env ENV, privateKey, publicKey string) (*Client, error) { + validENVs := []ENV{EnvProd, EnvDev, EnvStaging} + if !funk.Contains(validENVs, env) { + return nil, fmt.Errorf("globalcare.NewClient - invalid_env: %s", env) + } + pubKey, err := generatePublicKeyFromBytes([]byte(publicKey)) + if err != nil { + return nil, fmt.Errorf("globalcare.NewClient - invalid_public_key: %v", err) + } + privKey, err := generatePrivateKeyFromBytes([]byte(privateKey)) + if err != nil { + return nil, fmt.Errorf("globalcare.NewClient - invalid_private_key: %v", err) + } + return &Client{ + privateKey: privKey, + publicKey: pubKey, + }, nil +} + +// CreateOrder ... +func (c *Client) CreateOrder(p CreateOrderPayload) (*CommonResponse, error) { + url := c.getBaseURL() + apiPathCreateOrder + data := createOrderData{ + ProductCode: productCodeDefault, + ProviderID: providerIDDefault, + ProductID: productIDDefault, + PartnerID: p.PartnerOrderCode, + VehicleInfo: p.VehicleInfo, + InsuredInfo: p.InsuredInfo, + } + + body := CommonRequestBody{ + Signature: "", // TODO:implement + Data: base64.Encode(pjson.ToBytes(data)), + } + natsPayload := natsiomodel.NatsRequestHTTP{ + ResponseImmediately: true, + Payload: natsiomodel.HTTPPayload{ + URL: url, + Method: http.MethodPost, + Data: pjson.ToJSONString(body), + }, + } + msg, err := c.requestNats(constant.NatsCommunicationSubjectRequestHTTP, natsPayload) + if err != nil { + logger.Error("globalcare.Client.CreateOrder", logger.LogData{ + "err": err.Error(), + "payload": natsPayload, + }) + return nil, err + } + var ( + r natsiomodel.NatsResponse + res CommonResponse + ) + if err = pjson.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + err = r.ParseData(&res) + return &res, err +} + +// GetOrder ... +func (c *Client) GetOrder(orderCode string) (*CommonResponse, error) { + url := c.getBaseURL() + fmt.Sprintf(apiPathGetOrder, orderCode) + natsPayload := natsiomodel.NatsRequestHTTP{ + ResponseImmediately: true, + Payload: natsiomodel.HTTPPayload{ + URL: url, + Method: http.MethodGet, + }, + } + msg, err := c.requestNats(constant.NatsCommunicationSubjectRequestHTTP, natsPayload) + if err != nil { + logger.Error("globalcare.Client.GetOrder", logger.LogData{ + "err": err.Error(), + "payload": natsPayload, + }) + return nil, err + } + var ( + r natsiomodel.NatsResponse + res CommonResponse + ) + if err = pjson.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + err = r.ParseData(&res) + return &res, err +} + +func (c *Client) requestNats(subject string, data interface{}) (*nats.Msg, error) { + b := toBytes(data) + return c.natsClient.Request(subject, b) +} + +func (c *Client) getBaseURL() string { + return baseURLENVMapping[c.env] +} diff --git a/partnerapi/globalcare/model_request.go b/partnerapi/globalcare/model_request.go new file mode 100644 index 0000000..a520bb7 --- /dev/null +++ b/partnerapi/globalcare/model_request.go @@ -0,0 +1,43 @@ +package globalcare + +// CommonRequestBody ... +type CommonRequestBody struct { + Signature string `json:"signature"` + Data string `json:"data"` +} + +// CreateOrderPayload ... +type CreateOrderPayload struct { + PartnerOrderCode string `json:"partnerOrderCode"` + VehicleInfo VehicleInfo `json:"vehicleInfo"` + InsuredInfo InsuredInfo `json:"insuredInfo"` +} + +type createOrderData struct { + ProductCode string `json:"productCode"` + ProviderID int `json:"providerId"` + ProductID int `json:"productId"` + PartnerID string `json:"partnerId"` + VehicleInfo VehicleInfo `json:"vehicleInfo"` + InsuredInfo InsuredInfo `json:"insuredInfo"` +} + +// VehicleInfo ... +type VehicleInfo struct { + TypeID int `json:"typeId"` + TypeName string `json:"typeName"` + CarOccupantAccidentInsurance int `json:"carOccupantAccidentInsurance"` + License string `json:"license"` + Chassis string `json:"chassis"` + Engine string `json:"engine"` +} + +// InsuredInfo ... +type InsuredInfo struct { + BuyerName string `json:"buyerName"` + BuyerPhone string `json:"buyerPhone"` + BuyerEmail string `json:"buyerEmail"` + BuyerAddress string `json:"buyerAddress"` + YearsOfInsurance string `json:"yearsOfInsurance"` + BeginDate string `json:"beginDate"` +} diff --git a/partnerapi/globalcare/model_response.go b/partnerapi/globalcare/model_response.go new file mode 100644 index 0000000..ae17dff --- /dev/null +++ b/partnerapi/globalcare/model_response.go @@ -0,0 +1,8 @@ +package globalcare + +// CommonResponse ... +type CommonResponse struct { + StatusCode int `json:"statusCode"` + Message string `json:"message"` + Result interface{} `json:"result"` +} diff --git a/partnerapi/globalcare/nats.go b/partnerapi/globalcare/nats.go new file mode 100644 index 0000000..7ae04ff --- /dev/null +++ b/partnerapi/globalcare/nats.go @@ -0,0 +1 @@ +package globalcare diff --git a/partnerapi/globalcare/util.go b/partnerapi/globalcare/util.go new file mode 100644 index 0000000..f7896e4 --- /dev/null +++ b/partnerapi/globalcare/util.go @@ -0,0 +1,45 @@ +package globalcare + +import ( + "crypto/rsa" + "crypto/x509" + "encoding/json" + "encoding/pem" + "fmt" + + "github.com/Selly-Modules/logger" +) + +// toBytes ... +func toBytes(data interface{}) []byte { + b, err := json.Marshal(data) + if err != nil { + logger.Error("pjson.toBytes", logger.LogData{"payload": data}) + } + return b +} + +// toJSONString ... +func toJSONString(data interface{}) string { + return string(toBytes(data)) +} + +// GeneratePublicKeyFromBytes ... +func generatePublicKeyFromBytes(b []byte) (*rsa.PublicKey, error) { + pubPem, _ := pem.Decode(b) + p, err := x509.ParsePKIXPublicKey(pubPem.Bytes) + if err != nil { + return nil, fmt.Errorf("prsa.GeneratePublicKeyFromBytes: ParsePKIXPublicKey %v", err) + } + return p.(*rsa.PublicKey), nil +} + +// GeneratePrivateKeyFromBytes ... +func generatePrivateKeyFromBytes(b []byte) (*rsa.PrivateKey, error) { + privPem, _ := pem.Decode(b) + p, err := x509.ParsePKCS1PrivateKey(privPem.Bytes) + if err != nil { + return nil, fmt.Errorf("prsa.GeneratePrivateKeyFromBytes: ParsePKCS1PrivateKey %v", err) + } + return p, nil +} diff --git a/util/base64/base64.go b/util/base64/base64.go new file mode 100644 index 0000000..90a49ba --- /dev/null +++ b/util/base64/base64.go @@ -0,0 +1,15 @@ +package base64 + +import b64 "encoding/base64" + +// Encode ... +func Encode(data []byte) string { + sEnc := b64.StdEncoding.EncodeToString(data) + return sEnc +} + +// Decode ... +func Decode(text string) []byte { + sDec, _ := b64.StdEncoding.DecodeString(text) + return sDec +} diff --git a/util/pjson/bytes.go b/util/pjson/bytes.go new file mode 100644 index 0000000..86baedd --- /dev/null +++ b/util/pjson/bytes.go @@ -0,0 +1,16 @@ +package pjson + +import ( + "encoding/json" + + "github.com/Selly-Modules/logger" +) + +// ToBytes ... +func ToBytes(data interface{}) []byte { + b, err := json.Marshal(data) + if err != nil { + logger.Error("pjson.ToBytes", logger.LogData{"payload": data}) + } + return b +} diff --git a/util/pjson/string.go b/util/pjson/string.go new file mode 100644 index 0000000..c12797b --- /dev/null +++ b/util/pjson/string.go @@ -0,0 +1,6 @@ +package pjson + +// ToJSONString ... +func ToJSONString(data interface{}) string { + return string(ToBytes(data)) +} diff --git a/util/pjson/unmarshal.go b/util/pjson/unmarshal.go new file mode 100644 index 0000000..ca804f0 --- /dev/null +++ b/util/pjson/unmarshal.go @@ -0,0 +1,19 @@ +package pjson + +import ( + "encoding/json" + + "github.com/Selly-Modules/logger" +) + +// Unmarshal ... +func Unmarshal(b []byte, resultP interface{}) error { + err := json.Unmarshal(b, resultP) + if err != nil { + logger.Error("pjson.Unmarshal", logger.LogData{ + "raw": string(b), + "err": err.Error(), + }) + } + return err +}