diff --git a/go.mod b/go.mod index 330008db8..441919e45 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,14 @@ go 1.15 require ( cloud.google.com/go/firestore v1.6.1 // indirect firebase.google.com/go v3.13.0+incompatible + github.com/OpenIMSDK/getcdv3 v1.0.1 + github.com/OpenIMSDK/open_utils v1.0.8 github.com/Shopify/sarama v1.32.0 github.com/alibabacloud-go/darabonba-openapi v0.1.11 github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8 github.com/alibabacloud-go/sts-20150401 v1.1.0 github.com/alibabacloud-go/tea v1.1.17 - github.com/antonfisher/nested-logrus-formatter v1.3.0 + github.com/antonfisher/nested-logrus-formatter v1.3.1 github.com/aws/aws-sdk-go-v2 v1.16.7 github.com/aws/aws-sdk-go-v2/config v1.15.14 github.com/aws/aws-sdk-go-v2/credentials v1.12.9 @@ -28,10 +30,8 @@ require ( github.com/golang/protobuf v1.5.2 github.com/gorilla/websocket v1.4.2 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 - github.com/jinzhu/copier v0.3.4 - github.com/jonboulle/clockwork v0.2.2 // indirect + github.com/jinzhu/copier v0.3.5 github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible - github.com/lestrrat-go/strftime v1.0.4 // indirect github.com/minio/minio-go/v7 v7.0.22 github.com/mitchellh/mapstructure v1.4.2 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 @@ -41,7 +41,7 @@ require ( github.com/prometheus/client_golang v1.13.0 github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/robfig/cron/v3 v3.0.1 - github.com/sirupsen/logrus v1.8.1 + github.com/sirupsen/logrus v1.9.0 github.com/stretchr/testify v1.7.2 github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe github.com/swaggo/gin-swagger v1.5.0 @@ -49,19 +49,18 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.428 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.428 github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca - go.etcd.io/etcd/api/v3 v3.5.4 - go.etcd.io/etcd/client/v3 v3.5.4 + go.etcd.io/etcd/api/v3 v3.5.5 + go.etcd.io/etcd/client/v3 v3.5.5 go.mongodb.org/mongo-driver v1.8.3 go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.7.0 // indirect go.uber.org/zap v1.19.1 // indirect golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect - golang.org/x/image v0.0.0-20211028202545-6944b10bf410 + golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 golang.org/x/net v0.0.0-20220622184535-263ec571b305 - golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664 // indirect golang.org/x/tools v0.1.11 // indirect google.golang.org/api v0.59.0 - google.golang.org/grpc v1.45.0 + google.golang.org/grpc v1.49.0 google.golang.org/protobuf v1.28.1 gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df diff --git a/go.sum b/go.sum index c3a219fcb..39240da6f 100644 --- a/go.sum +++ b/go.sum @@ -54,7 +54,13 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/OpenIMSDK/getcdv3 v1.0.1 h1:0QikaWoVhc4LJk/LzR0DHV0ye367fpvt3iMhEqdLkf8= +github.com/OpenIMSDK/getcdv3 v1.0.1/go.mod h1:ZvsBwAjOZZr7HBF3SytJaHCltuOfBKbM1vLSCjut7kw= +github.com/OpenIMSDK/open_log v1.0.0 h1:ZQ908aWgPqfHOfkQ/oFSV20AZdRwPw+sZjC/sAPd5cA= +github.com/OpenIMSDK/open_log v1.0.0/go.mod h1:qWvqF4iT2qBAP1eGGbinc0aAng1Y25X8A9Si1WS3oB4= +github.com/OpenIMSDK/open_utils v1.0.1/go.mod h1:PPRayByXnfu8PR5Xv9wzUMBrm1BV3y7s29GGg8ae47s= +github.com/OpenIMSDK/open_utils v1.0.8 h1:IopxWgJwEF5ZAPsRuiZZOfcxNOQOCt/p8VDENcHN9r4= +github.com/OpenIMSDK/open_utils v1.0.8/go.mod h1:FLoaQblWUVKQgqt2LrNzfSZLT6D3DICBn1kcOMDLUOI= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/Shopify/sarama v1.29.0 h1:ARid8o8oieau9XrHI55f/L3EoRAhm9px6sonbD7yuUE= @@ -94,10 +100,9 @@ github.com/alibabacloud-go/tea-utils v1.3.9 h1:TtbzxS+BXrisA7wzbAMRtlU8A2eWLg0uf github.com/alibabacloud-go/tea-utils v1.3.9/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE= github.com/aliyun/credentials-go v1.1.2 h1:qU1vwGIBb3UJ8BwunHDRFtAhS6jnQLnde/yk0+Ih2GY= github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw= -github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/antonfisher/nested-logrus-formatter v1.3.0 h1:8zixYquU1Odk+vzAaAQPAdRh1ZjmUXNQ1T+dUBvlhVo= -github.com/antonfisher/nested-logrus-formatter v1.3.0/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA= +github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ= +github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA= github.com/aws/aws-sdk-go v1.38.3/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go-v2 v1.16.7 h1:zfBwXus3u14OszRxGcqCDS4MfMCv10e8SMJ2r8Xm0Ns= github.com/aws/aws-sdk-go-v2 v1.16.7/go.mod h1:6CpKuLXg2w7If3ABZCl/qZ6rEgwtjZTn4eAf4RcEyuw= @@ -146,6 +151,7 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -156,8 +162,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 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/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM= -github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dtm-labs/rockscache v0.0.11 h1:V6M+KH9fFRFDXgB+Uux1d6zwhZt1O34sgPwM0wjud9Y= @@ -178,9 +182,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= -github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= @@ -251,8 +254,6 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= -github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -302,6 +303,7 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -366,18 +368,17 @@ github.com/jcmturner/gokrb5/v8 v8.4.2 h1:6ZIM6b/JJN0X8UM43ZOM6Z4SJzla+a/u7scXFJz github.com/jcmturner/gokrb5/v8 v8.4.2/go.mod h1:sb+Xq/fTY5yktf/VxLsE3wlfPqQjp0aWNYyvBVK62bc= github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= -github.com/jinzhu/copier v0.3.4 h1:mfU6jI9PtCeUjkjQ322dlff9ELjGDu975C2p/nrubVI= -github.com/jinzhu/copier v0.3.4/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= +github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg= +github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= -github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= -github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= +github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg= +github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -419,10 +420,8 @@ github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2t github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4= github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA= -github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8= -github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g= -github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= -github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ= +github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw= github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w= github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -433,8 +432,6 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= -github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= 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/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4= @@ -539,8 +536,9 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= @@ -602,12 +600,12 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.etcd.io/etcd/api/v3 v3.5.4 h1:OHVyt3TopwtUQ2GKdd5wu3PmmipR4FTwCqoEjSyRdIc= -go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= -go.etcd.io/etcd/client/pkg/v3 v3.5.4 h1:lrneYvz923dvC14R54XcA7FXoZ3mlGZAgmwhfm7HqOg= -go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= -go.etcd.io/etcd/client/v3 v3.5.4 h1:p83BUL3tAYS0OT/r0qglgc3M1JjhM0diV8DSWAhVXv4= -go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY= +go.etcd.io/etcd/api/v3 v3.5.5 h1:BX4JIbQ7hl7+jL+g+2j5UAr0o1bctCm6/Ct+ArBGkf0= +go.etcd.io/etcd/api/v3 v3.5.5/go.mod h1:KFtNaxGDw4Yx/BA4iPPwevUTAuqcsPxzyX8PHydchN8= +go.etcd.io/etcd/client/pkg/v3 v3.5.5 h1:9S0JUVvmrVl7wCF39iTQthdaaNIiAaQbmK75ogO6GU8= +go.etcd.io/etcd/client/pkg/v3 v3.5.5/go.mod h1:ggrwbk069qxpKPq8/FKkQ3Xq9y39kbFR4LnKszpRXeQ= +go.etcd.io/etcd/client/v3 v3.5.5 h1:q++2WTJbUgpQu4B6hCuT7VkdwaTP7Qz6Daak3WzbrlI= +go.etcd.io/etcd/client/v3 v3.5.5/go.mod h1:aApjR4WGlSumpnJ2kloS75h6aHUmAyaPLjHMxpc7E7c= go.mongodb.org/mongo-driver v1.8.3 h1:TDKlTkGDKm9kkJVUOAXDK5/fkqKHJVwYQSpoRfB43R4= go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -632,11 +630,9 @@ go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= 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-20190325154230-a5d413f7728c/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-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -660,8 +656,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= -golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY= +golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= 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-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -689,7 +685,6 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -842,8 +837,8 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664 h1:wEZYwx+kK+KlZ0hpvP2Ls1Xr4+RWnlzGFwPP0aiDjIU= -golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1049,8 +1044,9 @@ google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQ google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M= -google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= +google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k= +google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= +google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= 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= diff --git a/internal/api_to_rpc/api.go b/internal/api_to_rpc/api.go index e7db3118b..65fc5cc6f 100644 --- a/internal/api_to_rpc/api.go +++ b/internal/api_to_rpc/api.go @@ -4,7 +4,6 @@ import ( "Open_IM/internal/fault_tolerant" "Open_IM/pkg/common/trace_log" "context" - "examination/pkg/api_struct" utils "github.com/OpenIMSDK/open_utils" "github.com/gin-gonic/gin" "net/http" diff --git a/internal/fault_tolerant/conn.go b/internal/fault_tolerant/conn.go index 78fa03f99..0d911346c 100644 --- a/internal/fault_tolerant/conn.go +++ b/internal/fault_tolerant/conn.go @@ -3,8 +3,8 @@ package fault_tolerant import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/log" - "Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/utils" + "github.com/OpenIMSDK/getcdv3" "google.golang.org/grpc" "strings" ) @@ -84,12 +84,12 @@ func GetConfigConn(serviceName string, operationID string) *grpc.ClientConn { return conn } -func GetDefaultConn(serviceName string, operationID string) *grpc.ClientConn { +func GetDefaultConn(serviceName string, operationID string) (*grpc.ClientConn, error) { con := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), serviceName, operationID, config.Config.Etcd.UserName, config.Config.Etcd.Password) if con != nil { - return con + return con, nil } log.NewWarn(operationID, utils.GetSelfFuncName(), "conn is nil !!!!!", serviceName) con = GetConfigConn(serviceName, operationID) - return con + return con, nil } diff --git a/pkg/grpc-etcdv3/getcdv3/pool.go b/pkg/grpc-etcdv3/getcdv3/pool.go deleted file mode 100644 index 943f4bd3f..000000000 --- a/pkg/grpc-etcdv3/getcdv3/pool.go +++ /dev/null @@ -1,254 +0,0 @@ -// Package grpcpool provides a pool of grpc clients -package getcdv3 - -import ( - "context" - "errors" - "sync" - "time" - - "google.golang.org/grpc" -) - -var ( - // ErrClosed is the error when the client pool is closed - ErrClosed = errors.New("grpc pool: client pool is closed") - // ErrTimeout is the error when the client pool timed out - ErrTimeout = errors.New("grpc pool: client pool timed out") - // ErrAlreadyClosed is the error when the client conn was already closed - ErrAlreadyClosed = errors.New("grpc pool: the connection was already closed") - // ErrFullPool is the error when the pool is already full - ErrFullPool = errors.New("grpc pool: closing a ClientConn into a full pool") -) - -// Factory is a function type creating a grpc client -type Factory func(schema, etcdaddr, servicename string) (*grpc.ClientConn, error) - -// FactoryWithContext is a function type creating a grpc client -// that accepts the context parameter that could be passed from -// Get or NewWithContext method. -type FactoryWithContext func(context.Context) (*grpc.ClientConn, error) - -// Pool is the grpc client pool -type Pool struct { - clients chan ClientConn - factory FactoryWithContext - idleTimeout time.Duration - maxLifeDuration time.Duration - mu sync.RWMutex -} - -// ClientConn is the wrapper for a grpc client conn -type ClientConn struct { - *grpc.ClientConn - pool *Pool - timeUsed time.Time - timeInitiated time.Time - unhealthy bool -} - -// New creates a new clients pool with the given initial and maximum capacity, -// and the timeout for the idle clients. Returns an error if the initial -// clients could not be created -func New(factory Factory, schema, etcdaddr, servicename string, init, capacity int, idleTimeout time.Duration, - maxLifeDuration ...time.Duration) (*Pool, error) { - return NewWithContext(context.Background(), func(ctx context.Context) (*grpc.ClientConn, error) { return factory(schema, etcdaddr, servicename) }, - init, capacity, idleTimeout, maxLifeDuration...) -} - -// NewWithContext creates a new clients pool with the given initial and maximum -// capacity, and the timeout for the idle clients. The context parameter would -// be passed to the factory method during initialization. Returns an error if the -// initial clients could not be created. -func NewWithContext(ctx context.Context, factory FactoryWithContext, init, capacity int, idleTimeout time.Duration, - maxLifeDuration ...time.Duration) (*Pool, error) { - - if capacity <= 0 { - capacity = 1 - } - if init < 0 { - init = 0 - } - if init > capacity { - init = capacity - } - p := &Pool{ - clients: make(chan ClientConn, capacity), - factory: factory, - idleTimeout: idleTimeout, - } - if len(maxLifeDuration) > 0 { - p.maxLifeDuration = maxLifeDuration[0] - } - for i := 0; i < init; i++ { - c, err := factory(ctx) - if err != nil { - return nil, err - } - - p.clients <- ClientConn{ - ClientConn: c, - pool: p, - timeUsed: time.Now(), - timeInitiated: time.Now(), - } - } - // Fill the rest of the pool with empty clients - for i := 0; i < capacity-init; i++ { - p.clients <- ClientConn{ - pool: p, - } - } - return p, nil -} - -func (p *Pool) getClients() chan ClientConn { - p.mu.RLock() - defer p.mu.RUnlock() - - return p.clients -} - -// Close empties the pool calling Close on all its clients. -// You can call Close while there are outstanding clients. -// The pool channel is then closed, and Get will not be allowed anymore -func (p *Pool) Close() { - p.mu.Lock() - clients := p.clients - p.clients = nil - p.mu.Unlock() - - if clients == nil { - return - } - - close(clients) - for client := range clients { - if client.ClientConn == nil { - continue - } - client.ClientConn.Close() - } -} - -// IsClosed returns true if the client pool is closed. -func (p *Pool) IsClosed() bool { - return p == nil || p.getClients() == nil -} - -// Get will return the next available client. If capacity -// has not been reached, it will create a new one using the factory. Otherwise, -// it will wait till the next client becomes available or a timeout. -// A timeout of 0 is an indefinite wait -func (p *Pool) Get(ctx context.Context) (*ClientConn, error) { - clients := p.getClients() - if clients == nil { - return nil, ErrClosed - } - - wrapper := ClientConn{ - pool: p, - } - select { - case wrapper = <-clients: - // All good - case <-ctx.Done(): - return nil, ErrTimeout // it would better returns ctx.Err() - } - - // If the wrapper was idle too long, close the connection and create a new - // one. It's safe to assume that there isn't any newer client as the client - // we fetched is the first in the channel - idleTimeout := p.idleTimeout - if wrapper.ClientConn != nil && idleTimeout > 0 && - wrapper.timeUsed.Add(idleTimeout).Before(time.Now()) { - - wrapper.ClientConn.Close() - wrapper.ClientConn = nil - } - - var err error - if wrapper.ClientConn == nil { - wrapper.ClientConn, err = p.factory(ctx) - if err != nil { - // If there was an error, we want to put back a placeholder - // client in the channel - clients <- ClientConn{ - pool: p, - } - } - // This is a new connection, reset its initiated time - wrapper.timeInitiated = time.Now() - } - - return &wrapper, err -} - -// Unhealthy marks the client conn as unhealthy, so that the connection -// gets reset when closed -func (c *ClientConn) Unhealthy() { - c.unhealthy = true -} - -// Close returns a ClientConn to the pool. It is safe to call multiple time, -// but will return an error after first time -func (c *ClientConn) Close() error { - if c == nil { - return nil - } - if c.ClientConn == nil { - return ErrAlreadyClosed - } - if c.pool.IsClosed() { - return ErrClosed - } - // If the wrapper connection has become too old, we want to recycle it. To - // clarify the logic: if the sum of the initialization time and the max - // duration is before Now(), it means the initialization is so old adding - // the maximum duration couldn't put in the future. This sum therefore - // corresponds to the cut-off point: if it's in the future we still have - // time, if it's in the past it's too old - maxDuration := c.pool.maxLifeDuration - if maxDuration > 0 && c.timeInitiated.Add(maxDuration).Before(time.Now()) { - c.Unhealthy() - } - - // We're cloning the wrapper so we can set ClientConn to nil in the one - // used by the user - wrapper := ClientConn{ - pool: c.pool, - ClientConn: c.ClientConn, - timeUsed: time.Now(), - } - if c.unhealthy { - wrapper.ClientConn.Close() - wrapper.ClientConn = nil - } else { - wrapper.timeInitiated = c.timeInitiated - } - select { - case c.pool.clients <- wrapper: - // All good - default: - return ErrFullPool - } - - c.ClientConn = nil // Mark as closed - return nil -} - -// Capacity returns the capacity -func (p *Pool) Capacity() int { - if p.IsClosed() { - return 0 - } - return cap(p.clients) -} - -// Available returns the number of currently unused clients -func (p *Pool) Available() int { - if p.IsClosed() { - return 0 - } - return len(p.clients) -} diff --git a/pkg/grpc-etcdv3/getcdv3/register.go b/pkg/grpc-etcdv3/getcdv3/register.go deleted file mode 100644 index 31af79b4a..000000000 --- a/pkg/grpc-etcdv3/getcdv3/register.go +++ /dev/null @@ -1,162 +0,0 @@ -package getcdv3 - -import ( - "Open_IM/pkg/common/config" - "Open_IM/pkg/common/log" - "Open_IM/pkg/utils" - "context" - "fmt" - clientv3 "go.etcd.io/etcd/client/v3" - "gopkg.in/yaml.v3" - "net" - "strconv" - "strings" - "time" -) - -type RegEtcd struct { - cli *clientv3.Client - ctx context.Context - cancel context.CancelFunc - key string -} - -var rEtcd *RegEtcd - -// "%s:///%s/" -func GetPrefix(schema, serviceName string) string { - return fmt.Sprintf("%s:///%s/", schema, serviceName) -} - -// "%s:///%s" -func GetPrefix4Unique(schema, serviceName string) string { - return fmt.Sprintf("%s:///%s", schema, serviceName) -} - -// "%s:///%s/" -> "%s:///%s:ip:port" -func RegisterEtcd4Unique(schema, etcdAddr, myHost string, myPort int, serviceName string, ttl int) error { - serviceName = serviceName + ":" + net.JoinHostPort(myHost, strconv.Itoa(myPort)) - return RegisterEtcd(schema, etcdAddr, myHost, myPort, serviceName, ttl) -} - -func GetTarget(schema, myHost string, myPort int, serviceName string) string { - return GetPrefix4Unique(schema, serviceName) + ":" + net.JoinHostPort(myHost, strconv.Itoa(myPort)) + "/" -} - -//etcdAddr separated by commas -func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName string, ttl int) error { - operationID := utils.OperationIDGenerator() - args := schema + " " + etcdAddr + " " + myHost + " " + serviceName + " " + utils.Int32ToString(int32(myPort)) - ttl = ttl * 3 - cli, err := clientv3.New(clientv3.Config{ - Endpoints: strings.Split(etcdAddr, ","), DialTimeout: 5 * time.Second}) - - log.Info(operationID, "RegisterEtcd args: ", args, ttl) - if err != nil { - log.Error(operationID, "clientv3.New failed ", args, ttl, err.Error()) - return fmt.Errorf("create etcd clientv3 client failed, errmsg:%v, etcd addr:%s", err, etcdAddr) - } - - //lease - ctx, cancel := context.WithCancel(context.Background()) - resp, err := cli.Grant(ctx, int64(ttl)) - if err != nil { - log.Error(operationID, "Grant failed ", err.Error(), ctx, ttl) - return fmt.Errorf("grant failed") - } - log.Info(operationID, "Grant ok, resp ID ", resp.ID) - - // schema:///serviceName/ip:port ->ip:port - serviceValue := net.JoinHostPort(myHost, strconv.Itoa(myPort)) - serviceKey := GetPrefix(schema, serviceName) + serviceValue - - //set key->value - if _, err := cli.Put(ctx, serviceKey, serviceValue, clientv3.WithLease(resp.ID)); err != nil { - log.Error(operationID, "cli.Put failed ", err.Error(), ctx, args, resp.ID) - return fmt.Errorf("put failed, errmsg:%v, key:%s, value:%s", err, serviceKey, serviceValue) - } - - //keepalive - kresp, err := cli.KeepAlive(ctx, resp.ID) - if err != nil { - log.Error(operationID, "KeepAlive failed ", err.Error(), args, resp.ID) - return fmt.Errorf("keepalive failed, errmsg:%v, lease id:%d", err, resp.ID) - } - log.Info(operationID, "RegisterEtcd ok ", args) - - go func() { - for { - select { - case pv, ok := <-kresp: - if ok == true { - log.Debug(operationID, "KeepAlive kresp ok", pv, args) - } else { - log.Error(operationID, "KeepAlive kresp failed ", pv, args) - t := time.NewTicker(time.Duration(ttl/2) * time.Second) - for { - select { - case <-t.C: - } - ctx, _ := context.WithCancel(context.Background()) - resp, err := cli.Grant(ctx, int64(ttl)) - if err != nil { - log.Error(operationID, "Grant failed ", err.Error(), args) - continue - } - - if _, err := cli.Put(ctx, serviceKey, serviceValue, clientv3.WithLease(resp.ID)); err != nil { - log.Error(operationID, "etcd Put failed ", err.Error(), args, " resp ID: ", resp.ID) - continue - } else { - log.Info(operationID, "etcd Put ok ", args, " resp ID: ", resp.ID) - } - } - } - } - } - }() - - rEtcd = &RegEtcd{ctx: ctx, - cli: cli, - cancel: cancel, - key: serviceKey} - - return nil -} - -func UnRegisterEtcd() { - //delete - rEtcd.cancel() - rEtcd.cli.Delete(rEtcd.ctx, rEtcd.key) -} - -func registerConf(key, conf string) { - etcdAddr := strings.Join(config.Config.Etcd.EtcdAddr, ",") - cli, err := clientv3.New(clientv3.Config{ - Endpoints: strings.Split(etcdAddr, ","), DialTimeout: 5 * time.Second}) - - if err != nil { - panic(err.Error()) - } - //lease - if _, err := cli.Put(context.Background(), key, conf); err != nil { - fmt.Println("panic, params: ") - panic(err.Error()) - } - -} - -func RegisterConf() { - bytes, err := yaml.Marshal(config.Config) - if err != nil { - panic(err.Error()) - } - secretMD5 := utils.Md5(config.Config.Etcd.Secret) - confBytes, err := utils.AesEncrypt(bytes, []byte(secretMD5[0:16])) - if err != nil { - panic(err.Error()) - } - fmt.Println("start register", secretMD5, GetPrefix(config.Config.Etcd.EtcdSchema, config.ConfName)) - registerConf(GetPrefix(config.Config.Etcd.EtcdSchema, config.ConfName), string(confBytes)) - fmt.Println("etcd register conf ok") -} diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go deleted file mode 100644 index ce987294f..000000000 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ /dev/null @@ -1,427 +0,0 @@ -package getcdv3 - -import ( - "Open_IM/pkg/common/config" - "Open_IM/pkg/common/log" - "Open_IM/pkg/utils" - "context" - "fmt" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - - //"go.etcd.io/etcd/mvcc/mvccpb" - //"google.golang.org/genproto/googleapis/ads/googleads/v1/services" - "strings" - "sync" - "time" - - "google.golang.org/grpc" - "google.golang.org/grpc/balancer/roundrobin" - "google.golang.org/grpc/resolver" -) - -type Resolver struct { - cc resolver.ClientConn - serviceName string - grpcClientConn *grpc.ClientConn - cli *clientv3.Client - schema string - etcdAddr string - watchStartRevision int64 -} - -var ( - nameResolver = make(map[string]*Resolver) - rwNameResolverMutex sync.RWMutex -) - -func NewResolver(schema, etcdAddr, serviceName string, operationID string) (*Resolver, error) { - etcdCli, err := clientv3.New(clientv3.Config{ - Endpoints: strings.Split(etcdAddr, ","), - Username: config.Config.Etcd.UserName, - Password: config.Config.Etcd.Password, - }) - if err != nil { - log.Error(operationID, "etcd client v3 failed") - return nil, utils.Wrap(err, "") - } - - var r Resolver - r.serviceName = serviceName - r.cli = etcdCli - r.schema = schema - r.etcdAddr = etcdAddr - resolver.Register(&r) - // - ctx, _ := context.WithTimeout(context.Background(), time.Second*5) - conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName), - grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), - grpc.WithInsecure()) - log.Debug(operationID, "etcd key ", GetPrefix(schema, serviceName)) - if err == nil { - r.grpcClientConn = conn - } - return &r, utils.Wrap(err, "") -} - -func (r1 *Resolver) ResolveNow(rn resolver.ResolveNowOptions) { -} - -func (r1 *Resolver) Close() { -} - -func getConn(schema, etcdaddr, serviceName string, operationID string) *grpc.ClientConn { - rwNameResolverMutex.RLock() - r, ok := nameResolver[schema+serviceName] - rwNameResolverMutex.RUnlock() - if ok { - log.Debug(operationID, "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r) - return r.grpcClientConn - } - - rwNameResolverMutex.Lock() - r, ok = nameResolver[schema+serviceName] - if ok { - rwNameResolverMutex.Unlock() - log.Debug(operationID, "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r) - return r.grpcClientConn - } - - r, err := NewResolver(schema, etcdaddr, serviceName, operationID) - if err != nil { - log.Error(operationID, "etcd failed ", schema, etcdaddr, serviceName, err.Error()) - rwNameResolverMutex.Unlock() - return nil - } - - log.Debug(operationID, "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r) - nameResolver[schema+serviceName] = r - rwNameResolverMutex.Unlock() - return r.grpcClientConn -} - -func GetConfigConn(serviceName string, operationID string) *grpc.ClientConn { - rpcRegisterIP := config.Config.RpcRegisterIP - var err error - if config.Config.RpcRegisterIP == "" { - rpcRegisterIP, err = utils.GetLocalIP() - if err != nil { - log.Error(operationID, "GetLocalIP failed ", err.Error()) - return nil - } - } - - var configPortList []int - //1 - if config.Config.RpcRegisterName.OpenImUserName == serviceName { - configPortList = config.Config.RpcPort.OpenImUserPort - } - //2 - if config.Config.RpcRegisterName.OpenImFriendName == serviceName { - configPortList = config.Config.RpcPort.OpenImFriendPort - } - //3 - if config.Config.RpcRegisterName.OpenImMsgName == serviceName { - configPortList = config.Config.RpcPort.OpenImMessagePort - } - //4 - if config.Config.RpcRegisterName.OpenImPushName == serviceName { - configPortList = config.Config.RpcPort.OpenImPushPort - } - //5 - if config.Config.RpcRegisterName.OpenImRelayName == serviceName { - configPortList = config.Config.RpcPort.OpenImMessageGatewayPort - } - //6 - if config.Config.RpcRegisterName.OpenImGroupName == serviceName { - configPortList = config.Config.RpcPort.OpenImGroupPort - } - //7 - if config.Config.RpcRegisterName.OpenImAuthName == serviceName { - configPortList = config.Config.RpcPort.OpenImAuthPort - } - //10 - if config.Config.RpcRegisterName.OpenImOfficeName == serviceName { - configPortList = config.Config.RpcPort.OpenImOfficePort - } - //11 - if config.Config.RpcRegisterName.OpenImOrganizationName == serviceName { - configPortList = config.Config.RpcPort.OpenImOrganizationPort - } - //12 - if config.Config.RpcRegisterName.OpenImConversationName == serviceName { - configPortList = config.Config.RpcPort.OpenImConversationPort - } - //13 - if config.Config.RpcRegisterName.OpenImCacheName == serviceName { - configPortList = config.Config.RpcPort.OpenImCachePort - } - //14 - if config.Config.RpcRegisterName.OpenImRealTimeCommName == serviceName { - configPortList = config.Config.RpcPort.OpenImRealTimeCommPort - } - if len(configPortList) == 0 { - log.Error(operationID, "len(configPortList) == 0 ") - return nil - } - target := rpcRegisterIP + ":" + utils.Int32ToString(int32(configPortList[0])) - log.Info(operationID, "rpcRegisterIP ", rpcRegisterIP, " port ", configPortList, " grpc target: ", target, " serviceName: ", serviceName) - conn, err := grpc.Dial(target, grpc.WithInsecure()) - if err != nil { - log.Error(operationID, "grpc.Dail failed ", err.Error()) - return nil - } - log.NewDebug(operationID, utils.GetSelfFuncName(), serviceName, conn) - return conn -} - -func GetDefaultConn(schema, etcdaddr, serviceName string, operationID string) (*grpc.ClientConn, error) { - con := getConn(schema, etcdaddr, serviceName, operationID) - if con != nil { - return con, nil - } - log.NewWarn(operationID, utils.GetSelfFuncName(), "conn is nil !!!!!", schema, etcdaddr, serviceName, operationID) - con = GetConfigConn(serviceName, operationID) - return con, nil -} - -func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) { - if r.cli == nil { - return nil, fmt.Errorf("etcd clientv3 client failed, etcd:%s", target) - } - r.cc = cc - log.Debug("", "Build..") - ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) - // "%s:///%s" - prefix := GetPrefix(r.schema, r.serviceName) - // get key first - resp, err := r.cli.Get(ctx, prefix, clientv3.WithPrefix()) - if err == nil { - var addrList []resolver.Address - for i := range resp.Kvs { - log.Debug("", "etcd init addr: ", string(resp.Kvs[i].Value)) - addrList = append(addrList, resolver.Address{Addr: string(resp.Kvs[i].Value)}) - } - r.cc.UpdateState(resolver.State{Addresses: addrList}) - r.watchStartRevision = resp.Header.Revision + 1 - go r.watch(prefix, addrList) - } else { - return nil, fmt.Errorf("etcd get failed, prefix: %s", prefix) - } - - return r, nil -} - -func (r *Resolver) Scheme() string { - return r.schema -} - -func exists(addrList []resolver.Address, addr string) bool { - for _, v := range addrList { - if v.Addr == addr { - return true - } - } - return false -} - -func remove(s []resolver.Address, addr string) ([]resolver.Address, bool) { - for i := range s { - if s[i].Addr == addr { - s[i] = s[len(s)-1] - return s[:len(s)-1], true - } - } - return nil, false -} - -func (r *Resolver) watch(prefix string, addrList []resolver.Address) { - rch := r.cli.Watch(context.Background(), prefix, clientv3.WithPrefix(), clientv3.WithPrefix()) - for n := range rch { - flag := 0 - for _, ev := range n.Events { - switch ev.Type { - case mvccpb.PUT: - if !exists(addrList, string(ev.Kv.Value)) { - flag = 1 - addrList = append(addrList, resolver.Address{Addr: string(ev.Kv.Value)}) - log.Debug("", "after add, new list: ", addrList) - } - case mvccpb.DELETE: - log.Debug("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value)) - i := strings.LastIndexAny(string(ev.Kv.Key), "/") - if i < 0 { - return - } - t := string(ev.Kv.Key)[i+1:] - log.Debug("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value), "addr:", t) - if s, ok := remove(addrList, t); ok { - flag = 1 - addrList = s - log.Debug("after remove, new list: ", addrList) - } - } - } - - if flag == 1 { - r.cc.UpdateState(resolver.State{Addresses: addrList}) - log.Debug("update: ", addrList) - } - } -} - -var Conn4UniqueList []*grpc.ClientConn -var Conn4UniqueListMtx sync.RWMutex -var IsUpdateStart bool -var IsUpdateStartMtx sync.RWMutex - -func GetDefaultGatewayConn4Unique(schema, etcdaddr, operationID string) []*grpc.ClientConn { - IsUpdateStartMtx.Lock() - if IsUpdateStart == false { - Conn4UniqueList = getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) - go func() { - for { - select { - case <-time.After(time.Second * time.Duration(30)): - Conn4UniqueListMtx.Lock() - Conn4UniqueList = getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) - Conn4UniqueListMtx.Unlock() - } - } - }() - } - IsUpdateStart = true - IsUpdateStartMtx.Unlock() - - Conn4UniqueListMtx.Lock() - var clientConnList []*grpc.ClientConn - for _, v := range Conn4UniqueList { - clientConnList = append(clientConnList, v) - } - Conn4UniqueListMtx.Unlock() - - //grpcConns := getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) - grpcConns := clientConnList - if len(grpcConns) > 0 { - return grpcConns - } - log.NewWarn(operationID, utils.GetSelfFuncName(), " len(grpcConns) == 0 ", schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) - grpcConns = GetDefaultGatewayConn4UniqueFromcfg(operationID) - log.NewDebug(operationID, utils.GetSelfFuncName(), config.Config.RpcRegisterName.OpenImRelayName, grpcConns) - return grpcConns -} - -func GetDefaultGatewayConn4UniqueFromcfg(operationID string) []*grpc.ClientConn { - rpcRegisterIP := config.Config.RpcRegisterIP - var err error - if config.Config.RpcRegisterIP == "" { - rpcRegisterIP, err = utils.GetLocalIP() - if err != nil { - log.Error("", "GetLocalIP failed ", err.Error()) - return nil - } - } - var conns []*grpc.ClientConn - configPortList := config.Config.RpcPort.OpenImMessageGatewayPort - for _, port := range configPortList { - target := rpcRegisterIP + ":" + utils.Int32ToString(int32(port)) - log.Info(operationID, "rpcRegisterIP ", rpcRegisterIP, " port ", configPortList, " grpc target: ", target, " serviceName: ", "msgGateway") - conn, err := grpc.Dial(target, grpc.WithInsecure()) - if err != nil { - log.Error(operationID, "grpc.Dail failed ", err.Error()) - continue - } - conns = append(conns, conn) - - } - return conns - -} - -func getConn4Unique(schema, etcdaddr, servicename string) []*grpc.ClientConn { - gEtcdCli, err := clientv3.New(clientv3.Config{Endpoints: strings.Split(etcdaddr, ",")}) - if err != nil { - log.Error("clientv3.New failed", err.Error()) - return nil - } - - ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) - // "%s:///%s" - prefix := GetPrefix4Unique(schema, servicename) - - resp, err := gEtcdCli.Get(ctx, prefix, clientv3.WithPrefix()) - // "%s:///%s:ip:port" -> %s:ip:port - allService := make([]string, 0) - if err == nil { - for i := range resp.Kvs { - k := string(resp.Kvs[i].Key) - - b := strings.LastIndex(k, "///") - k1 := k[b+len("///"):] - - e := strings.Index(k1, "/") - k2 := k1[:e] - allService = append(allService, k2) - } - } else { - gEtcdCli.Close() - //log.Error("gEtcdCli.Get failed", err.Error()) - return nil - } - gEtcdCli.Close() - - allConn := make([]*grpc.ClientConn, 0) - for _, v := range allService { - r := getConn(schema, etcdaddr, v, "0") - allConn = append(allConn, r) - } - - return allConn -} - -var ( - service2pool = make(map[string]*Pool) - service2poolMu sync.Mutex -) - -func GetconnFactory(schema, etcdaddr, servicename string) (*grpc.ClientConn, error) { - c := getConn(schema, etcdaddr, servicename, "0") - if c != nil { - return c, nil - } else { - return c, fmt.Errorf("GetConn failed") - } -} - -func GetConnPool(schema, etcdaddr, servicename string) (*ClientConn, error) { - //get pool - p := NewPool(schema, etcdaddr, servicename) - //poo->get - - ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(1000*time.Millisecond)) - - c, err := p.Get(ctx) - //log.Info("", "Get ", err) - return c, err - -} - -func NewPool(schema, etcdaddr, servicename string) *Pool { - - if _, ok := service2pool[schema+servicename]; !ok { - // - service2poolMu.Lock() - if _, ok1 := service2pool[schema+servicename]; !ok1 { - p, err := New(GetconnFactory, schema, etcdaddr, servicename, 5, 10, 1) - if err == nil { - service2pool[schema+servicename] = p - } - } - service2poolMu.Unlock() - } - - return service2pool[schema+servicename] -} -func GetGrpcConn(schema, etcdaddr, servicename string) *grpc.ClientConn { - return nameResolver[schema+servicename].grpcClientConn -}