diff --git a/go.mod b/go.mod index 6ffbf7e..192d1be 100644 --- a/go.mod +++ b/go.mod @@ -3,15 +3,18 @@ module github.com/imperiuse/golib go 1.15 require ( + github.com/Masterminds/squirrel v1.5.0 github.com/gomodule/redigo v1.8.3 github.com/gorilla/websocket v1.4.2 + github.com/jackc/pgx v3.6.2+incompatible github.com/jinzhu/copier v0.2.3 github.com/jmoiron/sqlx v1.3.1 github.com/lib/pq v1.9.0 github.com/mitchellh/mapstructure v1.4.1 - github.com/pkg/errors v0.9.1 + github.com/pkg/errors v0.8.1 github.com/sirupsen/logrus v1.7.0 github.com/stretchr/testify v1.5.1 gitlab.esta.spb.ru/arseny/golib v0.0.0-20200607220915-5e9c0d7fa129 + go.uber.org/zap v1.16.0 golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad ) diff --git a/go.sum b/go.sum index a9ab0c0..f56b30f 100644 --- a/go.sum +++ b/go.sum @@ -1,45 +1,280 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Masterminds/squirrel v1.5.0 h1:JukIZisrUXadA9pl3rMkjhiamxiB0cXiu+HGp/Y8cY8= +github.com/Masterminds/squirrel v1.5.0/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= +github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/containerd/containerd v1.4.3 h1:ijQT13JedHSHrQGWFcGEwzcNKrAGIiZ+jSD5QQG07SY= +github.com/containerd/containerd v1.4.3/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= +github.com/creack/pty v1.1.11/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/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= +github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v1.13.1 h1:IkZjBSIc8hBjLpqeAbeE5mca5mNgeatLHBy3GO78BWo= +github.com/docker/docker v20.10.2+incompatible h1:vFgEHPqWBTp4pTjdLwjAA4bSo3gvIGOYwuJTlEjVBCw= +github.com/docker/docker v20.10.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= +github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQV8= +github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw= +github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= +github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gofrs/uuid v1.2.0 h1:coDhrjgyJaglxSjxuJdqQSSdUpG3w6p1OwN2od6frBU= +github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= +github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +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.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/gomodule/redigo v1.8.3 h1:HR0kYDX2RJZvAup8CsiJwxB4dTCSC0AaUq6S4SiLwUc= github.com/gomodule/redigo v1.8.3/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +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.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 h1:vr3AYkKovP8uR8AvSGGUK1IDqRa5lAAvEkZG1LKaCRc= +github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ= +github.com/jackc/pgx v3.6.2+incompatible h1:2zP5OD7kiyR3xzRYMhOcXVvkDZsImVXfj+yIyTQf3/o= +github.com/jackc/pgx v3.6.2+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jinzhu/copier v0.2.3 h1:Oe09ju+9qft7TffZ7l/04AB2f8u1+V4ZMxmp/nnqeOs= github.com/jinzhu/copier v0.2.3/go.mod h1:24xnZezI2Yqac9J61UC6/dG/k76ttpq0DdJI3QmUvro= github.com/jmoiron/sqlx v1.3.1 h1:aLN7YINNZ7cYOPK3QC83dbM6KT0NMqVMw961TqrejlE= github.com/jmoiron/sqlx v1.3.1/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +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 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw= +github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o= +github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk= +github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8= github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 h1:rzf0wL0CHVc8CEsgyygG0Mn9CNCCPZqOPaz8RiiHYQk= +github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= +github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +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/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.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/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= +github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= +github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= +github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +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.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= gitlab.esta.spb.ru/arseny/golib v0.0.0-20200607220915-5e9c0d7fa129 h1:cq/u7vjhwZpSCQnLQm3tXB82l504KTPXP92Zn2oA2jQ= gitlab.esta.spb.ru/arseny/golib v0.0.0-20200607220915-5e9c0d7fa129/go.mod h1:0nALgauac6idxTyf1oAeE9k88A4sYGDFCehTt/botCw= +go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM= +go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e h1:JgcxKXxCjrA2tyDP/aNU9K0Ck5Czfk6C7e2tMw7+bSI= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +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-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +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-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +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-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +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/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/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-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE= +golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/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-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/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-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +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/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +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.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/reflect/orm/orm.go b/reflect/orm/orm.go index 4c1ea4e..8005c20 100644 --- a/reflect/orm/orm.go +++ b/reflect/orm/orm.go @@ -16,10 +16,12 @@ import ( // This micro library use the same approach like sqlx with `db` tag parsing // // Before start work with this package -// You should call function InitOrmMetaInfoCache() for warm and init cache (cacheMetaDTO) +// You should call function InitMetaTagInfoCache() for warm and init cache (cacheMetaDTO) type ( Column = string + Table = string + Typ = string Join = string Alias = string Argument = interface{} @@ -27,99 +29,139 @@ type ( structName = string ormUseInTagValue = string - metaDTO = struct { - colsMap map[ormUseInTagValue][]Column - aliases []Alias - join Join + MetaDTO = struct { + ColsMap map[ormUseInTagValue][]Column + Aliases []Alias + Join Join + TableName Table + StructName Typ } ) var ( m sync.RWMutex - cacheMetaDTO = map[structName]*metaDTO{} + cacheMetaDTO = map[structName]*MetaDTO{} ) // custom tag for "sugar" columns values prepare for Update squirrel library staff const ( - tagDB = "db" // must be for all DTO structs fields, this tag also used by sqlx - tagOrmUseIN = "orm_use_in" - tagOrmAlias = "orm_alias" - tagOrmJoin = "orm_join" + tagDB = "db" // must be for all DTO structs fields, this tag also used by sqlx + tagOrmUseIN = "orm_use_in" + tagOrmAlias = "orm_alias" + tagOrmJoin = "orm_join" + tagOrmTableName = "orm_table_name" ormUseInSelect = "select" ormUseInCreate = "create" ormUseInUpdate = "update" -) -const ( - emptyTypeParam = "" emptyRootAlias = "" ) -func InitOrmMetaInfoCache(objs ...interface{}) { +func InitMetaTagInfoCache(objs ...interface{}) { m.Lock() defer m.Unlock() for _, obj := range objs { - cacheMetaDTO[getObjTypeNameByReflect(obj)] = getMetaInfoForObj(obj) + if obj == nil { + continue + } + cacheMetaDTO[getObjTypeNameByReflect(obj)] = getNoneCacheMetaDTO(obj) + } +} + +func GetMetaDTO(obj interface{}) *MetaDTO { + return getMetaDTO(getObjTypeNameByReflect(obj), obj) +} + +func getMetaDTO(structName string, obj interface{}) *MetaDTO { + m.RLock() + if _, found := cacheMetaDTO[structName]; !found { + m.RUnlock() + m.Lock() + defer m.Unlock() + cacheMetaDTO[structName] = getNoneCacheMetaDTO(obj) + } else { + m.RUnlock() } + + return cacheMetaDTO[structName] } -func GetOrmDataForSelect(obj interface{}) ([]Column, []Alias, Join) { - meta := getMetaDTOInfo(emptyTypeParam, obj) - return meta.colsMap[ormUseInSelect], meta.aliases, meta.join +func GetDataForSelect(obj interface{}) ([]Column, []Alias, Join) { + meta := GetMetaDTO(obj) + return meta.ColsMap[ormUseInSelect], meta.Aliases, meta.Join } -func GetOrmDataForCreate(obj interface{}) ([]Column, []Argument, error) { +func GetDataForCreate(obj interface{}) ([]Column, []Argument) { cols, args := getMetaInfoUseInTag(obj, ormUseInCreate, emptyRootAlias) - return cols, args, nil + return cols, args } -func GetOrmDataForUpdate(obj interface{}) (map[Column]Argument, error) { +func GetDataForUpdate(obj interface{}) map[Column]Argument { cols, args := getMetaInfoUseInTag(obj, ormUseInUpdate, emptyRootAlias) cv := make(map[Column]Argument, len(cols)) for i, v := range cols { cv[v] = args[i] } - return cv, nil + return cv } -func getMetaInfoForObj(obj interface{}) *metaDTO { - meta := &metaDTO{ - colsMap: map[ormUseInTagValue][]Column{}, +func GetTableName(obj interface{}) string { + meta := GetMetaDTO(obj) + return meta.TableName +} + +func getNoneCacheMetaDTO(obj interface{}) *MetaDTO { + meta := &MetaDTO{ + ColsMap: map[ormUseInTagValue][]Column{ormUseInSelect: {}, ormUseInCreate: {}, ormUseInUpdate: {}}, + Aliases: []Alias{}, + Join: "", + TableName: "", + StructName: getObjTypeNameByReflect(obj), + } + if obj == nil { + return meta } - meta.join = getMetaInfoForOrmJoinTag(obj) + meta.Join = getMetaInfoForOrmTagOnlyOne(tagOrmJoin, obj) - meta.aliases = getMetaInfoForOrmAliasTag(obj) + meta.TableName = getMetaInfoForOrmTagOnlyOne(tagOrmTableName, obj) + + meta.Aliases = getMetaInfoForOrmAliasTag(obj) for _, v := range []string{ormUseInSelect, ormUseInCreate, ormUseInUpdate} { - meta.colsMap[v], _ = getMetaInfoUseInTag(obj, v, emptyRootAlias) + meta.ColsMap[v], _ = getMetaInfoUseInTag(obj, v, emptyRootAlias) } return meta } func getObjTypeNameByReflect(obj interface{}) string { + if obj == nil { + return "nil" + } return reflect.Indirect(reflect.ValueOf(obj)).Type().Name() } -func getMetaInfoForOrmJoinTag(obj interface{}) Join { - join := "" - +func getMetaInfoForOrmTagOnlyOne(value ormUseInTagValue, obj interface{}) string { v := reflect.Indirect(reflect.ValueOf(obj)) t := v.Type() + if t.Kind() != reflect.Struct { + return "" + } + for i := 0; i < t.NumField(); i++ { field := t.Field(i) - if tagValue := field.Tag.Get(tagOrmJoin); !isTagEmpty(tagValue) { - join = tagValue - continue // we search first join tag, for high root component only, + if tagValue := field.Tag.Get(value); !isTagEmpty(tagValue) { + return tagValue // we search first usage of tag, for high root component only, } } - return join + + return "" } func isTagEmpty(tag string) bool { @@ -132,6 +174,10 @@ func getMetaInfoForOrmAliasTag(obj interface{}) []Alias { v := reflect.Indirect(reflect.ValueOf(obj)) t := v.Type() + if t.Kind() != reflect.Struct { + return aliases + } + for i := 0; i < t.NumField(); i++ { field := t.Field(i) @@ -149,9 +195,17 @@ func getMetaInfoForOrmAliasTag(obj interface{}) []Alias { func getMetaInfoUseInTag(obj interface{}, useInTag ormUseInTagValue, alias Alias) ([]Column, []Argument) { cols, args := []Column{}, []Argument{} + if obj == nil { + return cols, args + } + v := reflect.Indirect(reflect.ValueOf(obj)) t := v.Type() + if t.Kind() != reflect.Struct { + return cols, args + } + for i := 0; i < t.NumField(); i++ { field := t.Field(i) @@ -191,22 +245,3 @@ func getMetaInfoUseInTag(obj interface{}, useInTag ormUseInTagValue, alias Alias return cols, args } - -func getMetaDTOInfo(typ string, obj interface{}) *metaDTO { - // todo think about typ param - if typ == emptyTypeParam { - typ = getObjTypeNameByReflect(obj) - } - - m.RLock() - if _, found := cacheMetaDTO[typ]; !found { - m.RUnlock() - m.Lock() - defer m.Unlock() - cacheMetaDTO[typ] = getMetaInfoForObj(obj) - } else { - m.RUnlock() - } - - return cacheMetaDTO[typ] -} diff --git a/reflect/orm/orm_test.go b/reflect/orm/orm_test.go index c44f632..ef96b40 100644 --- a/reflect/orm/orm_test.go +++ b/reflect/orm/orm_test.go @@ -13,6 +13,7 @@ type ( ID int64 `db:"id" orm_use_in:"select"` CreatedAt time.Time `db:"created_at" orm_use_in:"select"` UpdatedAt time.Time `db:"updated_at" orm_use_in:"select,update"` + _ bool `orm_use_in:"select,create,update"` } A struct { @@ -22,18 +23,20 @@ type ( UpdateOnly int `db:"update_field" orm_use_in:"update"` NoDbTagField string `orm_use_for:"update"` NoTagField string + _ bool `orm_table_name:"A"` } B struct { BaseDTO CUS float64 `db:"cus_field" orm_use_in:"create,update,select"` CUS2 int `db:"cus2_field" orm_use_in:"create,update,select"` + _ bool `orm_table_name:"B"` } C struct { A `orm_alias:"a"` B `orm_alias:"b"` - _ string `orm_join:"ON a.id = b.id"` + _ bool `orm_join:"ON a.id = b.id"` } BadStruct struct { @@ -48,42 +51,44 @@ const ( UpdateOnly = 123 ) -type ReflectTestSuit struct { +type OrmTestSuit struct { suite.Suite } -func (suite *ReflectTestSuit) SetupSuite() { - InitOrmMetaInfoCache([]interface{}{&A{}, &B{}, &C{}}...) +func (suite *OrmTestSuit) SetupSuite() { + InitMetaTagInfoCache([]interface{}{&A{}, &B{}, &C{}}...) + InitMetaTagInfoCache(new(interface{})) + InitMetaTagInfoCache(1, "", 1.23, &struct{}{}) + InitMetaTagInfoCache(nil) } // The TearDownSuite method will be run by testify once, at the very // end of the testing suite, after all tests have been run. -func (suite *ReflectTestSuit) TearDownSuite() { +func (suite *OrmTestSuit) TearDownSuite() { } // The SetupTest method will be run before every test in the suite. -func (suite *ReflectTestSuit) SetupTest() { +func (suite *OrmTestSuit) SetupTest() { } // The TearDownTest method will be run after every test in the suite. -func (suite *ReflectTestSuit) TearDownTest() { +func (suite *OrmTestSuit) TearDownTest() { } // In order for 'go test' to run this suite, we need to create // a normal test function and pass our suite to suite.Run func TestSuite(t *testing.T) { - suite.Run(t, new(ReflectTestSuit)) + suite.Run(t, new(OrmTestSuit)) } -func (suite *ReflectTestSuit) Test_GetOrmDataForCreate() { +func (suite *OrmTestSuit) Test_GetOrmDataForCreate() { t := suite.T() - cols, args, err := GetOrmDataForCreate(&A{ + cols, args := GetDataForCreate(&A{ SelectOnly: SelectOnly, CreateOnly: CreateOnly, UpdateOnly: UpdateOnly, }) - assert.Nil(t, err) assert.NotNil(t, cols) assert.NotNil(t, args) assert.Equal(t, len(cols), len(args)) @@ -91,40 +96,85 @@ func (suite *ReflectTestSuit) Test_GetOrmDataForCreate() { assert.NotNil(t, []string{"CreateOnly"}, args) } -func (suite *ReflectTestSuit) Test_GetOrmDataForSelect() { +func (suite *OrmTestSuit) Test_GetOrmDataForSelect() { t := suite.T() - cols, aliases, join := GetOrmDataForSelect(&C{}) + cols, aliases, join := GetDataForSelect(&C{}) assert.NotNil(t, aliases) assert.Equal(t, []string{"a", "b"}, aliases) assert.Equal(t, "ON a.id = b.id", join) assert.Equal(t, []string{"a.id as \"a.id\"", "a.created_at as \"a.created_at\"", "a.updated_at as \"a.updated_at\"", "a.select_field as \"a.select_field\"", "b.id as \"b.id\"", "b.created_at as \"b.created_at\"", "b.updated_at as \"b.updated_at\"", "b.cus_field as \"b.cus_field\"", "b.cus2_field as \"b.cus2_field\""}, cols) } -func (suite *ReflectTestSuit) Test_GetUpdateColumnsValues() { +func (suite *OrmTestSuit) Test_GetUpdateColumnsValues() { t := suite.T() - cv, err := GetOrmDataForUpdate(&A{ + cv := GetDataForUpdate(&A{ SelectOnly: SelectOnly, CreateOnly: CreateOnly, UpdateOnly: UpdateOnly, }) - assert.Nil(t, err) assert.NotNil(t, cv) assert.Equal(t, 2, len(cv)) assert.Equal(t, map[string]interface{}{"update_field": 123, "updated_at": time.Time{}}, cv) } -func (suite *ReflectTestSuit) Test_BadGetOrmDataForCreate() { +func (suite *OrmTestSuit) Test_BadGetOrmDataForCreate() { t := suite.T() - col, args, err := GetOrmDataForCreate(&BadStruct{}) - assert.Nil(t, err) + + col, args := GetDataForCreate(&BadStruct{}) + assert.Equal(t, []string{}, col) + assert.Equal(t, []interface{}{}, args) + + col, args = GetDataForCreate(nil) + assert.Equal(t, []string{}, col) + assert.Equal(t, []interface{}{}, args) + + col, args = GetDataForCreate(new(interface{})) + assert.Equal(t, []string{}, col) + assert.Equal(t, []interface{}{}, args) + + col, args = GetDataForCreate("123") + assert.Equal(t, []string{}, col) + assert.Equal(t, []interface{}{}, args) + + col, args = GetDataForCreate(123) assert.Equal(t, []string{}, col) assert.Equal(t, []interface{}{}, args) } -func (suite *ReflectTestSuit) Test_BadGetOrmDataForSelect() { +func (suite *OrmTestSuit) Test_BadGetOrmDataForSelect() { t := suite.T() - col, args, join := GetOrmDataForSelect(&BadStruct{}) + col, args, join := GetDataForSelect(&BadStruct{}) + assert.Equal(t, []string{}, col) + assert.Equal(t, []string{}, args) + assert.Equal(t, "", join) + + col, args, join = GetDataForSelect(nil) assert.Equal(t, []string{}, col) assert.Equal(t, []string{}, args) assert.Equal(t, "", join) + + col, args, join = GetDataForSelect(new(interface{})) + assert.Equal(t, []string{}, col) + assert.Equal(t, []string{}, args) + assert.Equal(t, "", join) + + col, args, join = GetDataForSelect(1234) + assert.Equal(t, []string{}, col) + assert.Equal(t, []string{}, args) + assert.Equal(t, "", join) + + col, args, join = GetDataForSelect("") + assert.Equal(t, []string{}, col) + assert.Equal(t, []string{}, args) + assert.Equal(t, "", join) + +} + +func (suite *OrmTestSuit) Test_GetTableName() { + t := suite.T() + + assert.Equal(t, "A", GetTableName(&A{})) + assert.Equal(t, "B", GetTableName(&B{})) + assert.Equal(t, "", GetTableName(&C{})) + assert.Equal(t, "", GetTableName(nil)) } diff --git a/sqlxhelper/helper.go b/sqlx/helper/helper.go similarity index 95% rename from sqlxhelper/helper.go rename to sqlx/helper/helper.go index 680efe5..78bb499 100644 --- a/sqlxhelper/helper.go +++ b/sqlx/helper/helper.go @@ -1,4 +1,4 @@ -package sqlxhelper +package helper import ( "context" diff --git a/sqlxhelper/transaction.go b/sqlx/helper/transaction.go similarity index 98% rename from sqlxhelper/transaction.go rename to sqlx/helper/transaction.go index 6c49d8b..59bf92a 100644 --- a/sqlxhelper/transaction.go +++ b/sqlx/helper/transaction.go @@ -1,4 +1,4 @@ -package sqlxhelper +package helper import ( "context" diff --git a/sqlx/repository/Makefile b/sqlx/repository/Makefile new file mode 100644 index 0000000..5d224bf --- /dev/null +++ b/sqlx/repository/Makefile @@ -0,0 +1,25 @@ +.EXPORT_ALL_VARIABLES: + +.PHONY: test_env_up +test_env_up: + @echo "Start test environment" + @echo "1. Export test env variables and Run docker-compose test" + docker-compose -f docker-compose.test.yml up -d + sleep 5 # sleep driven development, pg init + +.PHONY: test_env_down +test_env_down: + @echo "Stop test environment" + docker-compose -f docker-compose.test.yml down + +.PHONY: tests +tests: + @echo "Running integrations tests" + @echo "1. Run test env" + make test_env_up + + @echo "2. Run tests" + go test -timeout 5m -race -short `go list ./... ` + + @echo "3. Stop test env" + make test_env_down diff --git a/sqlx/repository/README.md b/sqlx/repository/README.md new file mode 100644 index 0000000..ecf1796 --- /dev/null +++ b/sqlx/repository/README.md @@ -0,0 +1,6 @@ +### For run integration test with real Postgres (docker container) + +``make tests`` + +For more information -> **Makefile** + diff --git a/sqlx/repository/docker-compose.test.yml b/sqlx/repository/docker-compose.test.yml new file mode 100644 index 0000000..5e40747 --- /dev/null +++ b/sqlx/repository/docker-compose.test.yml @@ -0,0 +1,17 @@ +version: '3' + +volumes: + test-postgres-data: {} + +services: + + test-postgres: + image: postgres:12 + container_name: test-postgres + environment: + - POSTGRES_USER=test + - POSTGRES_PASSWORD=test + volumes: + - test-postgres-data:/var/lib/postgresql/data + ports: #host_port : docker_port + - "5433:5432" # host_port:docker_port diff --git a/sqlx/repository/emptyRepo.go b/sqlx/repository/emptyRepo.go new file mode 100644 index 0000000..b21495c --- /dev/null +++ b/sqlx/repository/emptyRepo.go @@ -0,0 +1,75 @@ +package repository + +import ( + "database/sql" + "database/sql/driver" + + "github.com/jmoiron/sqlx" + "go.uber.org/zap" + + "github.com/imperiuse/golib/sqlx/repository/mocks" + "github.com/pkg/errors" + "github.com/stretchr/testify/mock" +) + +const ( + FakeStringAns = "fake_string_ans" +) + +var ( + ErrEmptyRepo = errors.New("repository: emptyRepo, can't found correct Repo by name or obj, please check arguments for methods Repo AutoRepo") + + emptyRepo = func() *repository { + + return &repository{ + logger: zap.NewNop(), + db: badMockDBConn, + name: "_emptyRepo_", + } + }() + + badMockDBConn = func() SqlxDBConnectorI { + // Interface SqlxDBConnectorI + // + //QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) + //QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) + //QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row + //ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) + //PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) + //BeginTxx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error) + //DriverName() string + //Rebind(string) string + //BindNamed(string, interface{}) (string, []interface{}, error) + + conn := mocks.SqlxDBConnectorI{} + mockCtxArg := mock.AnythingOfType("*context.cancelCtx") + mockStringArg := mock.AnythingOfType("string") + conn.On("DriverName").Return(FakeStringAns) + conn.On("Rebind", mockStringArg).Return(FakeStringAns) + conn.On("BindNamed", mockStringArg, mock.Anything).Return(FakeStringAns, nil, ErrEmptyRepo) + conn.On("QueryContext", mockCtxArg, mockStringArg, mock.Anything).Return(&sql.Rows{}, ErrEmptyRepo) + conn.On("QueryxContext", mockCtxArg, mockStringArg, mock.Anything).Return(&sqlx.Rows{}, ErrEmptyRepo) + conn.On("QueryRowxContext", mockCtxArg, mockStringArg, mock.Anything).Return(&sqlx.Row{}) + conn.On("ExecContext", mockCtxArg, mockStringArg, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(driver.RowsAffected(0), ErrEmptyRepo) + conn.On("PrepareContext", mockCtxArg, mockStringArg).Return(&sql.Stmt{}, ErrEmptyRepo) + conn.On("BeginTxx", mockCtxArg, mock.Anything).Return(&sqlx.Tx{}, ErrEmptyRepo) + + return &conn + }() + + goodMockDBConn = func() SqlxDBConnectorI { + conn := mocks.SqlxDBConnectorI{} + mockCtxArg := mock.AnythingOfType("*context.cancelCtx") + mockStringArg := mock.AnythingOfType("string") + conn.On("DriverName").Return(FakeStringAns) + conn.On("Rebind", mockStringArg).Return(FakeStringAns) + conn.On("BindNamed", mockStringArg, mock.Anything).Return(FakeStringAns, nil, nil) + conn.On("QueryContext", mockCtxArg, mockStringArg, mock.Anything).Return(&sql.Rows{}, nil) + conn.On("QueryxContext", mockCtxArg, mockStringArg, mock.Anything).Return(&sqlx.Rows{}, nil) + conn.On("QueryRowxContext", mockCtxArg, mockStringArg, mock.Anything).Return(&sqlx.Row{}) + conn.On("ExecContext", mockCtxArg, mockStringArg, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(driver.RowsAffected(0), nil) + conn.On("PrepareContext", mockCtxArg, mockStringArg).Return(&sql.Stmt{}, nil) + conn.On("BeginTxx", mockCtxArg, mock.Anything).Return(&sqlx.Tx{}, nil) + return &conn + }() +) diff --git a/sqlx/repository/factory.go b/sqlx/repository/factory.go new file mode 100644 index 0000000..be47425 --- /dev/null +++ b/sqlx/repository/factory.go @@ -0,0 +1,103 @@ +package repository + +import ( + "context" + "database/sql" + + "github.com/imperiuse/golib/reflect/orm" + + "github.com/Masterminds/squirrel" + "github.com/imperiuse/golib/sqlx/helper" + "github.com/jmoiron/sqlx" +) + +//go:generate mockery --name=SqlxDBConnectorI +type ( + SqlxDBConnectorI interface { + sqlx.QueryerContext + sqlx.ExecerContext + sqlx.ExtContext + sqlx.PreparerContext + helper.TxxI + } + + Repo = Table + + Repositories map[Repo]*repository + + DTO = interface{} + DTOID = interface { + Id() ID + } + + RepositoriesI interface { + Repo(Repo) Repository + AutoRepo(DTO) Repository + + AutoCreate(context.Context, DTOID) (ID, error) + AutoGet(context.Context, DTOID) error + AutoUpdate(context.Context, DTOID) (int64, error) + AutoDelete(context.Context, DTOID) (int64, error) + } + + Repository interface { + // Pure Sqlx Db Connector which we pass to NewSqlxMapRepo + SqlxDBConnectorI() SqlxDBConnectorI + + // usual "CRUD" + Create(context.Context, DTO) (ID, error) + Get(context.Context, ID, DTO) error + Update(context.Context, ID, DTO) (int64, error) + Delete(context.Context, ID) (int64, error) + + Insert(context.Context, []Column, []Argument) (int64, error) + UpdateCustom(context.Context, map[string]interface{}, squirrel.Eq) (int64, error) + FindBy(context.Context, []Column, squirrel.Eq, DTO) error + FindByWithInnerJoin(context.Context, []Column, Alias, Join, squirrel.Eq, DTO) error + + GetRowsByQuery(ctx context.Context, qb squirrel.SelectBuilder) (*sql.Rows, error) + CountByQuery(ctx context.Context, qb squirrel.SelectBuilder) (uint64, error) + } + + Column = string + + Argument = interface{} +) + +func NewSqlxMapRepo(logger ZapLogger, db SqlxDBConnectorI, tables ...Table) Repositories { + mapRepo := make(Repositories, len(tables)) + for _, name := range tables { + mapRepo[name] = newRepository(logger, db, name) + } + return mapRepo +} + +func (r Repositories) Repo(name Repo) Repository { + if rep, found := r[name]; found { + return rep + } + return emptyRepo +} + +func (r Repositories) AutoRepo(obj DTO) Repository { + if rep, found := r[orm.GetMetaDTO(obj).TableName]; found { + return rep + } + return emptyRepo +} + +func (r Repositories) AutoCreate(ctx context.Context, obj DTOID) (ID, error) { + return r.AutoRepo(obj).Create(ctx, obj) +} + +func (r Repositories) AutoUpdate(ctx context.Context, obj DTOID) (int64, error) { + return r.AutoRepo(obj).Update(ctx, obj.Id(), obj) +} + +func (r Repositories) AutoGet(ctx context.Context, obj DTOID) error { + return r.AutoRepo(obj).Get(ctx, obj.Id(), obj) +} + +func (r Repositories) AutoDelete(ctx context.Context, obj DTOID) (int64, error) { + return r.AutoRepo(obj).Delete(ctx, obj.Id()) +} diff --git a/sqlx/repository/mocks/SqlxDBConnectorI.go b/sqlx/repository/mocks/SqlxDBConnectorI.go new file mode 100644 index 0000000..ce1717f --- /dev/null +++ b/sqlx/repository/mocks/SqlxDBConnectorI.go @@ -0,0 +1,219 @@ +// Code generated by mockery v2.5.1. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + sql "database/sql" + + sqlx "github.com/jmoiron/sqlx" +) + +// SqlxDBConnectorI is an autogenerated mock type for the SqlxDBConnectorI type +type SqlxDBConnectorI struct { + mock.Mock +} + +// BeginTxx provides a mock function with given fields: ctx, opts +func (_m *SqlxDBConnectorI) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error) { + ret := _m.Called(ctx, opts) + + var r0 *sqlx.Tx + if rf, ok := ret.Get(0).(func(context.Context, *sql.TxOptions) *sqlx.Tx); ok { + r0 = rf(ctx, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*sqlx.Tx) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *sql.TxOptions) error); ok { + r1 = rf(ctx, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// BindNamed provides a mock function with given fields: _a0, _a1 +func (_m *SqlxDBConnectorI) BindNamed(_a0 string, _a1 interface{}) (string, []interface{}, error) { + ret := _m.Called(_a0, _a1) + + var r0 string + if rf, ok := ret.Get(0).(func(string, interface{}) string); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(string) + } + + var r1 []interface{} + if rf, ok := ret.Get(1).(func(string, interface{}) []interface{}); ok { + r1 = rf(_a0, _a1) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]interface{}) + } + } + + var r2 error + if rf, ok := ret.Get(2).(func(string, interface{}) error); ok { + r2 = rf(_a0, _a1) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// DriverName provides a mock function with given fields: +func (_m *SqlxDBConnectorI) DriverName() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// ExecContext provides a mock function with given fields: ctx, query, args +func (_m *SqlxDBConnectorI) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) { + var _ca []interface{} + _ca = append(_ca, ctx, query) + _ca = append(_ca, args...) + ret := _m.Called(_ca...) + + var r0 sql.Result + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) sql.Result); ok { + r0 = rf(ctx, query, args...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(sql.Result) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, ...interface{}) error); ok { + r1 = rf(ctx, query, args...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PrepareContext provides a mock function with given fields: ctx, query +func (_m *SqlxDBConnectorI) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) { + ret := _m.Called(ctx, query) + + var r0 *sql.Stmt + if rf, ok := ret.Get(0).(func(context.Context, string) *sql.Stmt); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*sql.Stmt) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// QueryContext provides a mock function with given fields: ctx, query, args +func (_m *SqlxDBConnectorI) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) { + var _ca []interface{} + _ca = append(_ca, ctx, query) + _ca = append(_ca, args...) + ret := _m.Called(_ca...) + + var r0 *sql.Rows + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) *sql.Rows); ok { + r0 = rf(ctx, query, args...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*sql.Rows) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, ...interface{}) error); ok { + r1 = rf(ctx, query, args...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// QueryRowxContext provides a mock function with given fields: ctx, query, args +func (_m *SqlxDBConnectorI) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row { + var _ca []interface{} + _ca = append(_ca, ctx, query) + _ca = append(_ca, args...) + ret := _m.Called(_ca...) + + var r0 *sqlx.Row + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) *sqlx.Row); ok { + r0 = rf(ctx, query, args...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*sqlx.Row) + } + } + + return r0 +} + +// QueryxContext provides a mock function with given fields: ctx, query, args +func (_m *SqlxDBConnectorI) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) { + var _ca []interface{} + _ca = append(_ca, ctx, query) + _ca = append(_ca, args...) + ret := _m.Called(_ca...) + + var r0 *sqlx.Rows + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) *sqlx.Rows); ok { + r0 = rf(ctx, query, args...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*sqlx.Rows) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, ...interface{}) error); ok { + r1 = rf(ctx, query, args...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Rebind provides a mock function with given fields: _a0 +func (_m *SqlxDBConnectorI) Rebind(_a0 string) string { + ret := _m.Called(_a0) + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} diff --git a/sqlx/repository/repository.go b/sqlx/repository/repository.go new file mode 100644 index 0000000..086b753 --- /dev/null +++ b/sqlx/repository/repository.go @@ -0,0 +1,281 @@ +package repository + +import ( + "context" + "database/sql" + "fmt" + "strconv" + + "github.com/imperiuse/golib/sqlx/helper" + + "go.uber.org/zap" + + "github.com/Masterminds/squirrel" + "github.com/imperiuse/golib/reflect/orm" + "github.com/jmoiron/sqlx" +) + +const ( + RowsAffectedUnknown = int64(0) + SerialUnknown = int64(0) +) + +type ( + Query = string + Alias = string + Join = string + + Table = string + + ID = interface{} +) + +type ( + ZapLogger = *zap.Logger + + repository struct { + logger ZapLogger + db SqlxDBConnectorI + name Repo + } +) + +func newRepository(logger ZapLogger, db SqlxDBConnectorI, tableName Table) *repository { + return &repository{ + logger: logger, + db: db, + name: tableName, + } +} + +func (r *repository) zapFieldRepo() zap.Field { + return zap.String("repo", r.name) +} + +func zapFieldObj(obj DTO) zap.Field { + return zap.Any("obj", obj) +} + +func zapFieldID(id ID) zap.Field { + return zap.Any("id", id) +} + +func ConvertIDToInt64(id interface{}) int64 { + if id == nil { + return int64(0) + } + + temp, err := strconv.Atoi(fmt.Sprint(id)) + if err != nil { + return int64(0) + } + + return int64(temp) +} + +func ConvertIDToString(id interface{}) string { + if id == nil { + return "0" + } + return fmt.Sprint(id) +} + +func (r *repository) SqlxDBConnectorI() SqlxDBConnectorI { + return r.db +} + +func (r *repository) Create(ctx context.Context, obj DTO) (ID, error) { + r.logger.Info("[repo.Create]", r.zapFieldRepo(), zapFieldObj(obj)) + + cols, vals := orm.GetDataForCreate(obj) + + query, args, err := squirrel.Insert(r.name). + Columns(cols...). + Values(vals...). + Suffix("RETURNING id"). + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return SerialUnknown, err + } + + var lastInsertID ID = int64(0) + return lastInsertID, r.create(ctx, query, &lastInsertID, args...) +} + +func (r *repository) create(ctx context.Context, query Query, lastInsertID *ID, args ...interface{}) error { + return helper.WithTransaction(ctx, nil, r.db, helper.InsertAndGetLastID(ctx, lastInsertID, query, args...)) +} + +func (r *repository) Get(ctx context.Context, id ID, dest DTO) error { + r.logger.Info("[repo.Get]", r.zapFieldRepo(), zapFieldID(id)) + query, args, err := squirrel.Select("*"). + From(r.name). + Where(squirrel.Eq{"id": id}). + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return err + } + + return sqlx.GetContext(ctx, r.db, dest, query, args...) +} + +func (r *repository) Update(ctx context.Context, id ID, obj DTO) (int64, error) { + r.logger.Info("[repo.Update]", r.zapFieldRepo(), zapFieldID(id), zapFieldObj(obj)) + + sm := orm.GetDataForUpdate(obj) + + query, args, err := squirrel.Update(r.name). + SetMap(sm). + Where(squirrel.Eq{"id": id}). + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return RowsAffectedUnknown, err + } + + res, err := r.db.ExecContext(ctx, query, args...) + if err != nil { + return RowsAffectedUnknown, err + } + + ra, err := res.RowsAffected() + if err != nil { + return RowsAffectedUnknown, err + } + + return ra, nil +} + +func (r *repository) Delete(ctx context.Context, id ID) (int64, error) { + r.logger.Info("[repo.Delete]", r.zapFieldRepo(), zapFieldID(id)) + + query, args, err := squirrel.Delete(r.name). + Where(squirrel.Eq{"id": id}). + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return RowsAffectedUnknown, err + } + + res, err := r.db.ExecContext(ctx, query, args...) + if err != nil { + return RowsAffectedUnknown, err + } + + ra, err := res.RowsAffected() + if err != nil { + return RowsAffectedUnknown, err + } + + return ra, nil +} + +func (r *repository) Insert(ctx context.Context, columns []string, values []interface{}) (int64, error) { + r.logger.Info("[repo.Insert]", r.zapFieldRepo(), zap.Any("columns", columns), zap.Any("values", values)) + + query, args, err := squirrel.Insert(r.name). + Columns(columns...). + Values(values...). + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return 0, err + } + + res, err := r.db.ExecContext(ctx, query, args...) + if err != nil { + return RowsAffectedUnknown, err + } + + return res.RowsAffected() +} + +func (r *repository) UpdateCustom(ctx context.Context, set map[string]interface{}, condition squirrel.Eq) (int64, error) { + r.logger.Info("[repo.UpdateCustom]", r.zapFieldRepo(), zap.Any("set_map", set), zap.Any("condition", condition)) + + query, args, err := squirrel.Update(r.name). + SetMap(set). + Where(condition). + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return RowsAffectedUnknown, err + } + + res, err := r.db.ExecContext(ctx, query, args...) + if err != nil { + return RowsAffectedUnknown, err + } + + ra, err := res.RowsAffected() + if err != nil { + return RowsAffectedUnknown, err + } + + return ra, nil +} + +func (r *repository) FindBy(ctx context.Context, columns []string, condition squirrel.Eq, target interface{}) error { + r.logger.Info("[repo.FindBy]", r.zapFieldRepo(), zap.Any("columns", columns), zap.Any("condition", condition)) + + query, args, err := squirrel.Select(columns...). + From(r.name). + Where(condition). + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return err + } + + return sqlx.SelectContext(ctx, r.db, target, query, args...) +} + +func (r *repository) FindByWithInnerJoin(ctx context.Context, columns []string, alias string, join string, condition squirrel.Eq, target interface{}) error { + r.logger.Info("[repo.FindByWithInnerJoin]", r.zapFieldRepo(), + zap.Any("columns", columns), + zap.Any("join", join), + zap.Any("condition", condition)) + + query, args, err := squirrel.Select(columns...). + From(r.name + " as " + alias). + InnerJoin(join). + Where(condition). + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return err + } + + return sqlx.GetContext(ctx, r.db, target, query, args...) +} + +func (r *repository) GetRowsByQuery(ctx context.Context, qb squirrel.SelectBuilder) (*sql.Rows, error) { + r.logger.Info("[repo.GetRowsByQuery]", r.zapFieldRepo(), zap.Any("qb", qb)) + + query, args, err := qb. + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return nil, err + } + + return r.db.QueryContext(ctx, query, args...) +} + +func (r *repository) CountByQuery(ctx context.Context, qb squirrel.SelectBuilder) (uint64, error) { + r.logger.Info("[repo.CountByQuery]", r.zapFieldRepo(), zap.Any("qb", qb)) + + query, args, err := qb. + PlaceholderFormat(squirrel.Dollar). + ToSql() + if err != nil { + return 0, err + } + + counter := uint64(0) + err = r.db.QueryRowxContext(ctx, query, args...).Scan(&counter) + + return counter, err +} diff --git a/sqlx/repository/repository_test.go b/sqlx/repository/repository_test.go new file mode 100644 index 0000000..e9cf946 --- /dev/null +++ b/sqlx/repository/repository_test.go @@ -0,0 +1,522 @@ +package repository + +import ( + "context" + "database/sql" + "fmt" + "testing" + "time" + + _ "github.com/jackc/pgx/stdlib" + + "github.com/Masterminds/squirrel" + "github.com/imperiuse/golib/reflect/orm" + "github.com/jmoiron/sqlx" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "go.uber.org/zap" +) + +const ( + PostgresUser = "test" + PostgresPassword = "test" + PostgresDB = "test" + PostgresHost = "localhost" + PostgresPort = "5433" +) + +type RepositoryTestSuit struct { + suite.Suite + ctx context.Context + ctxCancel context.CancelFunc + logger *zap.Logger + repos Repositories + db *sqlx.DB + goodMockDb SqlxDBConnectorI + badMockDb SqlxDBConnectorI +} + +// DTO +type ( + Integer = int64 + + NotDTO struct{} + + BaseDTO struct { + ID Integer `db:"id" orm_use_in:"select"` + CreatedAt time.Time `db:"created_at" orm_use_in:"select"` + UpdatedAt time.Time `db:"updated_at" orm_use_in:"select,update"` + } + + User struct { + BaseDTO + Name string `db:"name" orm_use_in:"select,create,update"` + Email string `db:"email" orm_use_in:"select,create,update"` + Password string `db:"password" orm_use_in:"select,create,update"` + RoleID Integer `db:"role_id" orm_use_in:"select,create,update"` + _ bool `orm_table_name:"Users"` + } + + Role struct { + BaseDTO + Name string `db:"name" orm_use_in:"select,create,update"` + Rights int `db:"rights" orm_use_in:"select,create,update"` + _ bool `orm_table_name:"Roles"` + } + + UsersRole struct { + User `db:"u" orm_alias:"u"` + Role `db:"r" orm_alias:"r"` + _ bool `orm_join:" ON u.role_id = r.id "` + } +) + +func (b *BaseDTO) Id() interface{} { + return b.ID +} + +var DSL = map[string]string{ + "Roles": `CREATE TABLE IF NOT EXISTS Roles +( +id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, +created_at TIMESTAMP NOT NULL DEFAULT NOW(), +updated_at TIMESTAMP NOT NULL DEFAULT NOW(), +name TEXT NOT NULL, +rights INTEGER NOT NULL +);`, + "Users": `CREATE TABLE IF NOT EXISTS Users +( +id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, +created_at TIMESTAMP NOT NULL DEFAULT NOW(), +updated_at TIMESTAMP NOT NULL DEFAULT NOW(), +name TEXT NOT NULL, +email TEXT NOT NULL, +password TEXT NOT NULL, +role_id INTEGER NOT NULL, +CONSTRAINT fkey__r FOREIGN KEY (role_id) REFERENCES roles (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE +);`, +} + +var DTOs = []interface{}{&User{}, &Role{}} + +// The SetupSuite method will be run by testify once, at the very +// start of the testing suite, before any tests are run. +func (suite *RepositoryTestSuit) SetupSuite() { + suite.ctx, suite.ctxCancel = context.WithCancel(context.Background()) + suite.logger = zap.NewNop() + + suite.badMockDb = badMockDBConn + suite.goodMockDb = goodMockDBConn + + dsn := fmt.Sprintf("postgres://%s:%s@%s:%s/%s", + PostgresUser, + PostgresPassword, + PostgresHost, + PostgresPort, + PostgresDB, + ) + + db, err := sqlx.Connect("pgx", dsn) + assert.Nil(suite.T(), err) + assert.NotNil(suite.T(), db) + + suite.db = db + + orm.InitMetaTagInfoCache(DTOs...) + orm.InitMetaTagInfoCache(&BaseDTO{}, &UsersRole{}) + + tables := []string{} + // create table + for _, obj := range DTOs { + table := orm.GetTableName(obj) + assert.NotEqual(suite.T(), "", table) + tables = append(tables, table) + + _, err = db.ExecContext(suite.ctx, DSL[table]) + assert.Nil(suite.T(), err) + } + + // Refresh DB + for _, table := range tables { + _, err = db.ExecContext(suite.ctx, fmt.Sprintf("TRUNCATE TABLE %s RESTART IDENTITY CASCADE;", table)) + assert.Nil(suite.T(), err) + } + + suite.repos = NewSqlxMapRepo(suite.logger, db, tables...) + assert.NotNil(suite.T(), suite.repos) + +} + +// The TearDownSuite method will be run by testify once, at the very +// end of the testing suite, after all tests have been run. +func (suite *RepositoryTestSuit) TearDownSuite() { + for _, obj := range DTOs { + id, err := suite.repos.AutoRepo(obj).Delete(suite.ctx, 1) + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), int64(0), id) + } + + assert.Nil(suite.T(), suite.db.Close()) +} + +// The SetupTest method will be run before every test in the suite. +func (suite *RepositoryTestSuit) SetupTest() { + suite.ctx, suite.ctxCancel = context.WithCancel(context.Background()) +} + +// The TearDownTest method will be run after every test in the suite. +func (suite *RepositoryTestSuit) TearDownTest() { +} + +// In order for 'go test' to run this suite, we need to create +// a normal test function and pass our suite to suite.Run +func TestSuite(t *testing.T) { + suite.Run(t, new(RepositoryTestSuit)) +} + +func (suite *RepositoryTestSuit) Test_Repo_AutoRepo_SqlxDBConnectorI() { + t := suite.T() + + for _, obj := range DTOs { + assert.NotNil(t, suite.repos.AutoRepo(obj).SqlxDBConnectorI()) + assert.Equal(t, suite.db, suite.repos.AutoRepo(obj).SqlxDBConnectorI()) + assert.NotEqual(t, suite.repos.AutoRepo(obj), suite.repos.Repo("_UNKNOWN_")) + assert.Equal(t, emptyRepo, suite.repos.Repo("_UNKNOWN_")) + assert.Equal(t, emptyRepo, suite.repos.Repo("_UNKNOWN_2")) + assert.Equal(t, emptyRepo, suite.repos.AutoRepo(&BaseDTO{})) + assert.Equal(t, emptyRepo, suite.repos.AutoRepo(&NotDTO{})) + } + + assert.Equal(t, suite.repos.Repo(orm.GetTableName(&User{})), suite.repos.AutoRepo(User{})) + assert.NotNil(t, suite.repos.Repo(orm.GetTableName(&User{}))) + assert.Equal(t, suite.repos.Repo(orm.GetTableName(&Role{})), suite.repos.AutoRepo(Role{})) + assert.NotNil(t, suite.repos.Repo(orm.GetTableName(&Role{}))) +} + +func (suite *RepositoryTestSuit) Test_EmptyRepo_NotPanic() { + t := suite.T() + + r := suite.repos.Repo("_UNKNOWN_") + assert.NotNil(t, r) + assert.Equal(t, r, emptyRepo) + + assert.NotNil(t, r.SqlxDBConnectorI()) + assert.NotEqual(t, suite.db, r.SqlxDBConnectorI()) + + emptyCon := r.SqlxDBConnectorI() + + assert.Equal(t, FakeStringAns, emptyCon.DriverName()) + + assert.Equal(t, FakeStringAns, emptyCon.Rebind("")) + + r1, r2, r3 := emptyCon.BindNamed("", nil) + assert.Equal(t, FakeStringAns, r1) + assert.Nil(t, r2) + assert.Equal(t, ErrEmptyRepo, r3) + + row, err := emptyCon.QueryxContext(suite.ctx, "select * from users;") + assert.NotNil(t, row) + assert.Equal(t, ErrEmptyRepo, err) + + row2, err := emptyCon.QueryContext(suite.ctx, "select * from users;") + assert.Equal(t, ErrEmptyRepo, err) + assert.NotNil(t, row2) + + assert.Equal(t, &sqlx.Row{}, emptyCon.QueryRowxContext(suite.ctx, "select * from users;")) + + res, err := emptyCon.ExecContext(suite.ctx, "select * from users;") + assert.Equal(t, ErrEmptyRepo, err) + assert.NotNil(t, res) + + stmt, err := emptyCon.PrepareContext(suite.ctx, "select * from users;") + assert.Equal(t, ErrEmptyRepo, err) + assert.NotNil(t, stmt) + + tx, err := emptyCon.BeginTxx(suite.ctx, nil) + assert.Equal(t, ErrEmptyRepo, err) + assert.NotNil(t, tx) + + // CHECK REPO CRUD + + var role Role + assert.Equal(t, sql.ErrNoRows, r.Get(suite.ctx, 1, &role)) + + id, err := r.Create(suite.ctx, &role) + assert.Equal(t, ErrEmptyRepo, err) + assert.Equal(t, int64(0), id) + + cnt, err := r.Update(suite.ctx, 1, &role) + assert.NotNil(t, err) + assert.Equal(t, int64(0), cnt) + + cnt, err = r.Delete(suite.ctx, 1) + assert.NotNil(t, err) + assert.Equal(t, int64(0), cnt) + + var temp interface{} + err = r.FindBy(suite.ctx, []Column{"*"}, squirrel.Eq{"id": 1}, &temp) + assert.NotNil(t, err) + + ucnt, err := r.CountByQuery(suite.ctx, squirrel.Select("*").From("unknown")) + assert.NotNil(t, err) + assert.Equal(t, uint64(0), ucnt) + + err = r.FindByWithInnerJoin(suite.ctx, []Column{"*"}, "al", "ON al.id = p.id", squirrel.Eq{"id": 1}, &temp) + assert.NotNil(t, err) + + rows1, err := r.GetRowsByQuery(suite.ctx, squirrel.Select("*").From("unknown")) + assert.NotNil(t, err) + assert.NotNil(t, rows1) + + id, err = r.Insert(suite.ctx, []Column{"name"}, []interface{}{"test"}) + assert.NotNil(t, err) + assert.Equal(t, int64(0), id) + + cnt, err = r.UpdateCustom(suite.ctx, map[string]interface{}{}, squirrel.Eq{"id": 1}) + assert.NotNil(t, err) + assert.Equal(t, int64(0), cnt) +} + +func (suite *RepositoryTestSuit) Test_CRUD() { + t := suite.T() + + const ( + rights = 10 + role1 = "role1" + updatedRole1 = "role1_updated" + ) + + var role = Role{ + Name: role1, + Rights: rights, + } + + id, err := suite.repos.AutoRepo(&role).Create(suite.ctx, &role) + assert.Nil(t, err) + assert.NotNil(t, id) + + // Alternative way + id2, err := suite.repos.AutoCreate(suite.ctx, &role) + assert.Nil(t, err) + assert.NotNil(t, id2) + // also you can directly get Repo Role and exec method Create + assert.NotNil(t, suite.repos.Repo("Roles")) + //suite.repos.Repo("Roles").Create(.....) + + var temp Role + err = suite.repos.AutoRepo(&temp).Get(suite.ctx, id, &temp) + assert.Nil(t, err) + assert.Equal(t, role.Name, temp.Name) + assert.Equal(t, role.Rights, temp.Rights) + assert.NotNil(t, temp.UpdatedAt) + assert.NotNil(t, temp.CreatedAt) + assert.NotNil(t, temp.ID) + assert.Equal(t, id, temp.ID) + + // Alternative way to get obj from db + var temp2 = Role{ + BaseDTO: BaseDTO{ID: id.(Integer)}, + } + err = suite.repos.AutoGet(suite.ctx, &temp2) + assert.Nil(t, err) + assert.Equal(t, temp, temp2) + + var temp3 Role + err = suite.repos.Repo(orm.GetTableName(&temp3)).Get(suite.ctx, id, &temp3) + assert.Nil(t, err) + assert.Equal(t, temp, temp3) + + role.Name = updatedRole1 + cnt, err := suite.repos.AutoRepo(&role).Update(suite.ctx, id, &role) + assert.Nil(t, err) + assert.Equal(t, int64(1), cnt) + err = suite.repos.AutoRepo(&temp).Get(suite.ctx, id, &temp) + assert.Nil(t, err) + assert.Equal(t, role.Name, temp.Name) + + cnt, err = suite.repos.AutoRepo(&role).Delete(suite.ctx, id) + assert.Nil(t, err) + assert.Equal(t, int64(1), cnt) + + err = suite.repos.Repo("Roles").Get(suite.ctx, id2, &temp) + assert.Nil(t, err) + assert.NotNil(t, temp.ID) + + temp.Name = "" + cnt, err = suite.repos.AutoUpdate(suite.ctx, &temp) + assert.Nil(t, err) + assert.Equal(t, int64(1), cnt) + + temp2.ID = temp.ID + assert.Nil(t, suite.repos.AutoGet(suite.ctx, &temp2)) + assert.Equal(t, temp, temp2) + + cnt, err = suite.repos.AutoDelete(suite.ctx, &temp) + assert.Nil(t, err) + assert.Equal(t, int64(1), cnt) +} + +func (suite *RepositoryTestSuit) Test_Advance_RepoFunc() { + t := suite.T() + ctx := suite.ctx + + // Create one role, than create one user, than check Join, Cnt + var role = Role{ + Name: "new_test_role", + Rights: 100, + } + roleID, err := suite.repos.AutoCreate(ctx, &role) + defer func() { _, _ = suite.repos.AutoRepo(&role).Delete(ctx, roleID) }() + assert.Nil(t, err) + assert.NotNil(t, roleID) + + const newName = "newTestRole" + // Check Update Custom + cnt, err := suite.repos.AutoRepo(&role).UpdateCustom(ctx, map[string]interface{}{"name": newName}, squirrel.Eq{"id": roleID}) + assert.Nil(t, err) + assert.Equal(t, int64(1), cnt) + + var roles []Role + assert.Nil(t, suite.repos.AutoRepo(&role).FindBy(ctx, []Column{"rights"}, squirrel.Eq{"id": roleID}, &roles)) + assert.Equal(t, 1, len(roles)) + assert.NotEqual(t, newName, roles[0].Name, "role name must not change, because we have not updated name yet ") + + roles = roles[1:] + assert.Nil(t, suite.repos.AutoRepo(&role).FindBy(ctx, []Column{"name"}, squirrel.Eq{"id": roleID}, &roles)) + assert.Equal(t, 1, len(roles)) + assert.Equal(t, newName, roles[0].Name, "role name must change, because we have updated name already ") + + var user = User{ + Name: "testUser", + Email: "test@test.ru", + Password: "123456", + RoleID: roleID.(int64), + } + + userID, err := suite.repos.AutoCreate(ctx, &user) + defer func() { _, _ = suite.repos.AutoRepo(&user).Delete(ctx, userID) }() + assert.Nil(t, err) + assert.NotNil(t, userID) + + cols, aliases, join := orm.GetDataForSelect(&UsersRole{}) + join = orm.GetTableName(&Role{}) + " as " + aliases[1] + " " + join + var ur UsersRole + err = suite.repos.AutoRepo(&user).FindByWithInnerJoin(ctx, cols, aliases[0], join, squirrel.Eq{"u.id": userID}, &ur) + assert.Nil(t, err) + assert.NotNil(t, ur) + assert.Equal(t, userID, ur.User.ID) + assert.Equal(t, user.Name, ur.User.Name) + assert.Equal(t, user.Email, ur.User.Email) + assert.Equal(t, user.Password, ur.User.Password) + assert.Equal(t, user.RoleID, ur.Role.ID) + assert.Equal(t, role.Rights, ur.Role.Rights) + + // Insert one more user with same role + + var role2 = Role{ + Name: "role2", + Rights: 50, + } + cols, args := orm.GetDataForCreate(role2) + role2ID, err := suite.repos.AutoRepo(&role2).Insert(ctx, cols, args) + assert.Nil(t, err) + assert.NotNil(t, role2ID) + defer func() { _, _ = suite.repos.AutoRepo(&role).Delete(ctx, role2ID) }() + + { + cnt, err := suite.repos.AutoRepo(&role2).CountByQuery(ctx, squirrel.Select("count(1)").From(orm.GetTableName(&role2))) + assert.Nil(t, err) + assert.Equal(t, uint64(2), cnt) + + _, err = suite.repos.AutoRepo(&role2).CountByQuery(ctx, squirrel.Select("*").From(orm.GetTableName(&role2))) + assert.NotNil(t, err) + + _, err = suite.repos.AutoRepo(&role2).CountByQuery(ctx, squirrel.Select("*")) + assert.NotNil(t, err) + } + + rows, err := suite.repos.AutoRepo(&role2).GetRowsByQuery(ctx, squirrel.Select("*").From(orm.GetTableName(&role2))) + assert.Nil(t, err) + assert.NotNil(t, rows) +} + +func (suite *RepositoryTestSuit) Test_GetAllPossibleErrors() { + t := suite.T() + ctx := suite.ctx + + _, err := suite.repos.AutoRepo(&Role{}).CountByQuery(ctx, squirrel.Select()) + assert.NotNil(t, err) + + _, err = suite.repos.AutoRepo(&Role{}).GetRowsByQuery(ctx, squirrel.Select()) + assert.NotNil(t, err) + + { + err = suite.repos.AutoRepo(&User{}).FindByWithInnerJoin(ctx, []string{}, "", "", squirrel.Eq{}, nil) + assert.NotNil(t, err) + } + + assert.NotNil(t, suite.repos.AutoRepo(&User{}).FindBy(ctx, []string{}, squirrel.Eq{}, nil)) + + { + id, err := suite.repos.AutoRepo(&User{}).Insert(ctx, []string{}, []interface{}{}) + assert.NotNil(t, err) + assert.Equal(t, int64(0), id) + } + + { + id, err := suite.repos.AutoRepo(&User{}).Create(ctx, new(interface{})) + assert.NotNil(t, err) + assert.Equal(t, int64(0), id) + + id, err = suite.repos.AutoRepo(&User{}).Create(ctx, nil) + assert.NotNil(t, err) + assert.Equal(t, int64(0), id) + + id, err = suite.repos.AutoRepo(&User{}).Create(ctx, &NotDTO{}) + assert.NotNil(t, err) + assert.Equal(t, int64(0), id) + } + +} + +func (suite *RepositoryTestSuit) Test_ConvertFunc() { + t := suite.T() + + tests := []struct { + Input interface{} + OutInt int64 + OutStr string + }{ + { + Input: 0, + OutInt: 0, + OutStr: "0", + }, + { + Input: 123, + OutInt: 123, + OutStr: "123", + }, + { + Input: "123", + OutInt: 123, + OutStr: "123", + }, + { + Input: 1.23, + OutInt: 0, + OutStr: "1.23", + }, + { + Input: nil, + OutInt: 0, + OutStr: "0", + }, + } + + for _, v := range tests { + assert.Equal(t, v.OutInt, ConvertIDToInt64(v.Input)) + assert.Equal(t, v.OutStr, ConvertIDToString(v.Input)) + } + +}