From 9683ee12204d4adb8d6b2958eaf4327e1060986c Mon Sep 17 00:00:00 2001 From: houseme Date: Sat, 9 Apr 2022 21:50:11 +0800 Subject: [PATCH 01/70] feat: ID is the unique instance ID as registered. --- net/gsvc/gsvc.go | 1 + 1 file changed, 1 insertion(+) diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index da86aaf440e..7457b15de2b 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -49,6 +49,7 @@ type Watcher interface { // Service definition. type Service struct { + ID string // ID is the unique instance ID as registered. `json:"id"` Prefix string // Service prefix. Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. Namespace string // Service Namespace, to indicate different service in the same environment with the same Name. From 03eea9138162314bc881fd374967e4a4cd725e4f Mon Sep 17 00:00:00 2001 From: houseme Date: Mon, 11 Apr 2022 19:15:36 +0800 Subject: [PATCH 02/70] improve --- net/gsvc/gsvc.go | 1 - os/gstructs/gstructs_field.go | 2 +- util/gvalid/gvalid_custom_rule.go | 4 ++-- util/gvalid/gvalid_validator_check_struct.go | 24 ++++++++++---------- util/gvalid/gvalid_validator_check_value.go | 6 ++--- util/gvalid/gvalid_validator_message.go | 2 +- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index 7457b15de2b..da86aaf440e 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -49,7 +49,6 @@ type Watcher interface { // Service definition. type Service struct { - ID string // ID is the unique instance ID as registered. `json:"id"` Prefix string // Service prefix. Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. Namespace string // Service Namespace, to indicate different service in the same environment with the same Name. diff --git a/os/gstructs/gstructs_field.go b/os/gstructs/gstructs_field.go index 6e28c07c8c5..b1a3ee64b1a 100644 --- a/os/gstructs/gstructs_field.go +++ b/os/gstructs/gstructs_field.go @@ -107,7 +107,7 @@ func (f *Field) OriginalKind() reflect.Kind { return kind } -// Fields retrieves and returns the fields of `pointer` as slice. +// Fields retrieve and return the fields of `pointer` as slice. func Fields(in FieldsInput) ([]Field, error) { var ( ok bool diff --git a/util/gvalid/gvalid_custom_rule.go b/util/gvalid/gvalid_custom_rule.go index 2521eb4bff7..9c5a9dfdd4c 100644 --- a/util/gvalid/gvalid_custom_rule.go +++ b/util/gvalid/gvalid_custom_rule.go @@ -41,7 +41,7 @@ var ( customRuleFuncMap = make(map[string]RuleFunc) ) -// RegisterRule registers custom validation rule and function for package. +// RegisterRule registers custom validation rules and function for package. func RegisterRule(rule string, f RuleFunc) { if customRuleFuncMap[rule] != nil { intlog.PrintFunc(context.TODO(), func() string { @@ -54,7 +54,7 @@ func RegisterRule(rule string, f RuleFunc) { customRuleFuncMap[rule] = f } -// RegisterRuleByMap registers custom validation rules using map for package. +// RegisterRuleByMap registers custom validation rules using maps for package. func RegisterRuleByMap(m map[string]RuleFunc) { for k, v := range m { customRuleFuncMap[k] = v diff --git a/util/gvalid/gvalid_validator_check_struct.go b/util/gvalid/gvalid_validator_check_struct.go index 42244db40a2..1ae842b082e 100644 --- a/util/gvalid/gvalid_validator_check_struct.go +++ b/util/gvalid/gvalid_validator_check_struct.go @@ -22,7 +22,7 @@ import ( func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error { var ( errorMaps = make(map[string]map[string]error) // Returning error. - fieldToAliasNameMap = make(map[string]string) // Field names to alias name map. + fieldToAliasNameMap = make(map[string]string) // Field names to alias name maps. resultSequenceRules = make([]fieldRule, 0) isEmptyData = empty.IsEmpty(v.data) isEmptyAssoc = empty.IsEmpty(v.assoc) @@ -36,7 +36,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error return newValidationErrorByStr(internalObjectErrRuleName, err) } - // It here must use gstructs.TagFields not gstructs.FieldMap to ensure error sequence. + // It here must use gstructs.TagFields not gstructs.FieldMap to ensure error sequences. tagFields, err := gstructs.TagFields(object, structTagPriority) if err != nil { return newValidationErrorByStr(internalObjectErrRuleName, err) @@ -51,7 +51,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error checkRules = make([]fieldRule, 0) nameToRuleMap = make(map[string]string) // just for internally searching index purpose. customMessage = make(CustomMsg) // Custom rule error message map. - checkValueData = v.assoc // Ready to be validated data, which can be type of . + checkValueData = v.assoc // Ready to be validated data, which can be types of. ) if checkValueData == nil { checkValueData = object @@ -71,7 +71,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error ruleArray = strings.Split(rule, "|") ) for k, ruleKey := range ruleArray { - // If length of custom messages is lesser than length of rules, + // If the length of custom messages is less than the length of rules, // the rest rules use the default error messages. if len(msgArray) <= k { continue @@ -93,7 +93,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error }) } - // Map type rules does not support sequence. + // Map type rule does not support sequences. // Format: map[key]rule case map[string]string: nameToRuleMap = assertValue @@ -114,7 +114,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error } else { inputParamMap = gconv.Map(v.assoc) } - // Checks and extends the parameters map with struct alias tag. + // Checks and extend the parameter map with struct alias tag. if !v.useAssocInsteadOfObjectAttributes { for nameOrTag, field := range fieldMap { inputParamMap[nameOrTag] = field.Value.Interface() @@ -125,7 +125,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error } // Merge the custom validation rules with rules in struct tag. - // The custom rules has the most high priority that can overwrite the struct tag rules. + // The custom rules have the highest priority that can overwrite the struct tag rules. for _, field := range tagFields { var ( isMeta bool @@ -144,7 +144,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error // It uses the alias name from validation rule. fieldToAliasNameMap[fieldName] = name } - // It here extends the params map using alias names. + // It is here extends the params map using alias names. // Note that the variable `name` might be alias name or attribute name. if _, ok := inputParamMap[name]; !ok { if !v.useAssocInsteadOfObjectAttributes { @@ -194,7 +194,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error ruleArray = strings.Split(rule, "|") ) for k, ruleKey := range ruleArray { - // If length of custom messages is lesser than length of rules, + // If the length of custom messages is less than the length of rules, // the rest rules use the default error messages. if len(msgArray) <= k { continue @@ -229,7 +229,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error // It checks the struct recursively if its attribute is a struct/struct slice. for _, field := range fieldMap { - // No validation interface implements check. + // No validation interface implements checks. if _, ok := field.Value.Interface().(iNoValidation); ok { continue } @@ -239,7 +239,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error } if field.IsEmbedded() { if err = v.doCheckStruct(ctx, field.Value); err != nil { - // It merges the errors into single error map. + // It merges the errors into a single error map. for k, m := range err.(*validationError).errors { errorMaps[k] = m } @@ -292,7 +292,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error } } } - // It checks each rule and its value in loop. + // It checks each rule and its value in the loop. if validatedError := v.doCheckValue(ctx, doCheckValueInput{ Name: checkRuleItem.Name, Value: value, diff --git a/util/gvalid/gvalid_validator_check_value.go b/util/gvalid/gvalid_validator_check_value.go index bd69f9f77ce..4041d2e5bac 100644 --- a/util/gvalid/gvalid_validator_check_value.go +++ b/util/gvalid/gvalid_validator_check_value.go @@ -37,14 +37,14 @@ type doCheckValueInput struct { Name string // Name specifies the name of parameter `value`. Value interface{} // Value specifies the value for the rules to be validated. Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. - Messages interface{} // Messages specifies the custom error messages for this rule from parameters input, which is usually type of map/slice. - DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be type of map/struct or a nil value. + Messages interface{} // Messages specifies the custom error messages for this rule from parameter input, which is usually the type of map/slice. + DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be the type of map/struct or a nil value. DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally } // doCheckSingleValue does the really rules validation for single key-value. func (v *Validator) doCheckValue(ctx context.Context, in doCheckValueInput) Error { - // If there's no validation rules, it does nothing and returns quickly. + // If there are no validation rules, it does nothing and returns quickly. if in.Rule == "" { return nil } diff --git a/util/gvalid/gvalid_validator_message.go b/util/gvalid/gvalid_validator_message.go index 30cab76d8d1..ee860deb365 100644 --- a/util/gvalid/gvalid_validator_message.go +++ b/util/gvalid/gvalid_validator_message.go @@ -21,7 +21,7 @@ func (v *Validator) getErrorMessageByRule(ctx context.Context, ruleKey string, c } return content } - // Retrieve default message according to certain rule. + // Retrieve default messages according to certain rule. content = v.i18nManager.GetContent(ctx, ruleMessagePrefixForI18n+ruleKey) if content == "" { content = defaultMessages[ruleKey] From 934fb58d57d7ca00e0eb20ec8d777acb4e632be3 Mon Sep 17 00:00:00 2001 From: houseme Date: Mon, 18 Apr 2022 23:48:18 +0800 Subject: [PATCH 03/70] feat:create polarismesh --- contrib/registry/polaris/go.mod | 10 + contrib/registry/polaris/go.sum | 290 ++++++++++++++ contrib/registry/polaris/polaris.go | 1 + contrib/registry/polaris/registry.go | 438 ++++++++++++++++++++++ contrib/registry/polaris/registry_test.go | 208 ++++++++++ 5 files changed, 947 insertions(+) create mode 100644 contrib/registry/polaris/go.mod create mode 100644 contrib/registry/polaris/go.sum create mode 100644 contrib/registry/polaris/polaris.go create mode 100644 contrib/registry/polaris/registry.go create mode 100644 contrib/registry/polaris/registry_test.go diff --git a/contrib/registry/polaris/go.mod b/contrib/registry/polaris/go.mod new file mode 100644 index 00000000000..ae0009fd7db --- /dev/null +++ b/contrib/registry/polaris/go.mod @@ -0,0 +1,10 @@ +module github.com/gogf/gf/contrib/registry/polaris/v2 + +go 1.16 + +require ( + github.com/gogf/gf/v2 v2.0.6 + github.com/polarismesh/polaris-go v1.0.2 +) + +replace github.com/gogf/gf/v2 => ../../../ diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum new file mode 100644 index 00000000000..a2361b12cb5 --- /dev/null +++ b/contrib/registry/polaris/go.sum @@ -0,0 +1,290 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= +github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= +github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E= +github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +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-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +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/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/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.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= +github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= +github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= +github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= +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.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +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/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc= +github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg= +github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2/go.mod h1:pDgmNM6seYpwvPos3q+zxlXMsbve6mOIPucUnUOrI7Y= +github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks= +github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= +github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= +github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs= +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/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= +github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +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/longbridgeapp/sqlparser v0.3.1 h1:iWOZWGIFgQrJRgobLXUNJdvqGRpbVXkyKUKUA5CNJBE= +github.com/longbridgeapp/sqlparser v0.3.1/go.mod h1:GIHaUq8zvYyHLCLMJJykx1CdM6LHtkUih/QaJXySSx4= +github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +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-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= +github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= +github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/polarismesh/polaris-go v1.0.2 h1:vMPTgO+DKNq9mC5HP7wFnlotIqg2waOAIKQq0qoZchY= +github.com/polarismesh/polaris-go v1.0.2/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +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= +go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= +go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= +go.opentelemetry.io/otel/sdk v1.0.0 h1:BNPMYUONPNbLneMttKSjQhOTlFLOD9U22HNG1KrIN2Y= +go.opentelemetry.io/otel/sdk v1.0.0/go.mod h1:PCrDHlSy5x1kjezSdL37PhbFUMjrsLRshJ2zCzeXwbM= +go.opentelemetry.io/otel/trace v1.0.0 h1:TSBr8GTEtKevYMG/2d21M989r5WJYVimhTHBKVEZuh4= +go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4= +go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI= +go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +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/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/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-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +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-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/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-20180909124046-d0be0721c37e/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-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= +golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= +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-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +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-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +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.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A= +google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +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/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +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= diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go new file mode 100644 index 00000000000..9bcac4ada3b --- /dev/null +++ b/contrib/registry/polaris/polaris.go @@ -0,0 +1 @@ +package polaris diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go new file mode 100644 index 00000000000..b1b5cd4742d --- /dev/null +++ b/contrib/registry/polaris/registry.go @@ -0,0 +1,438 @@ +package polaris + +import ( + "context" + "fmt" + "net" + "net/url" + "strconv" + "strings" + "time" + + "github.com/polarismesh/polaris-go/api" + "github.com/polarismesh/polaris-go/pkg/config" + "github.com/polarismesh/polaris-go/pkg/model" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gsvc" +) + +var ( + _ gsvc.Registrar = &Registry{} +) + +// _instanceIDSeparator Instance id Separator. +const _instanceIDSeparator = "-" + +type options struct { + // required, namespace in polaris + Namespace string + + // required, service access token + ServiceToken string + + // optional, protocol in polaris. Default value is nil, it means use protocol config in service + Protocol *string + + // service weight in polaris. Default value is 100, 0 <= weight <= 10000 + Weight int + + // service priority. Default value is 0. The smaller the value, the lower the priority + Priority int + + // To show service is healthy or not. Default value is True . + Healthy bool + + // Heartbeat enable .Not in polaris . Default value is True. + Heartbeat bool + + // To show service is isolate or not. Default value is False . + Isolate bool + + // TTL timeout. if node needs to use heartbeat to report,required. If not set,server will throw ErrorCode-400141 + TTL int + + // optional, Timeout for single query. Default value is global config + // Total is (1+RetryCount) * Timeout + Timeout time.Duration + + // optional, retry count. Default value is global config + RetryCount int +} + +// Option The option is a polaris option. +type Option func(o *options) + +// Registry is polaris registry. +type Registry struct { + opt options + provider api.ProviderAPI + consumer api.ConsumerAPI +} + +// WithNamespace with the Namespace option. +func WithNamespace(namespace string) Option { + return func(o *options) { o.Namespace = namespace } +} + +// WithServiceToken with ServiceToken option. +func WithServiceToken(serviceToken string) Option { + return func(o *options) { o.ServiceToken = serviceToken } +} + +// WithProtocol with the Protocol option. +func WithProtocol(protocol string) Option { + return func(o *options) { o.Protocol = &protocol } +} + +// WithWeight with the Weight option. +func WithWeight(weight int) Option { + return func(o *options) { o.Weight = weight } +} + +// WithHealthy with the Healthy option. +func WithHealthy(healthy bool) Option { + return func(o *options) { o.Healthy = healthy } +} + +// WithIsolate with the Isolate option. +func WithIsolate(isolate bool) Option { + return func(o *options) { o.Isolate = isolate } +} + +// WithTTL with the TTL option. +func WithTTL(TTL int) Option { + return func(o *options) { o.TTL = TTL } +} + +// WithTimeout the Timeout option. +func WithTimeout(timeout time.Duration) Option { + return func(o *options) { o.Timeout = timeout } +} + +// WithRetryCount with RetryCount option. +func WithRetryCount(retryCount int) Option { + return func(o *options) { o.RetryCount = retryCount } +} + +// WithHeartbeat with the Heartbeat option. +func WithHeartbeat(heartbeat bool) Option { + return func(o *options) { o.Heartbeat = heartbeat } +} + +func NewRegistry(provider api.ProviderAPI, consumer api.ConsumerAPI, opts ...Option) (r *Registry) { + op := options{ + Namespace: "default", + ServiceToken: "", + Protocol: nil, + Weight: 0, + Priority: 0, + Healthy: true, + Heartbeat: true, + Isolate: false, + TTL: 0, + Timeout: 0, + RetryCount: 0, + } + for _, option := range opts { + option(&op) + } + return &Registry{ + opt: op, + provider: provider, + consumer: consumer, + } +} + +// NewRegistryWithConfig new a registry with config. +func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Registry) { + provider, err := api.NewProviderAPIByConfig(conf) + if err != nil { + panic(err) + } + consumer, err := api.NewConsumerAPIByConfig(conf) + if err != nil { + panic(err) + } + return NewRegistry(provider, consumer, opts...) +} + +// Register the registration. +func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { + ids := make([]string, 0, len(serviceInstance.Endpoints)) + for _, endpoint := range serviceInstance.Endpoints { + // get url + u, err := url.Parse(endpoint) + if err != nil { + return err + } + + // get host and port + host, port, err := net.SplitHostPort(u.Host) + if err != nil { + return err + } + + // port to int + portNum, err := strconv.Atoi(port) + if err != nil { + return err + } + + // medata + var rmd map[string]string + if serviceInstance.Metadata == nil { + rmd = map[string]string{ + "kind": u.Scheme, + "version": serviceInstance.Version, + } + } else { + rmd = make(map[string]string, len(serviceInstance.Metadata)+2) + for k, v := range serviceInstance.Metadata { + rmd[k] = v + } + rmd["kind"] = u.Scheme + rmd["version"] = serviceInstance.Version + } + // Register + service, err := r.provider.Register( + &api.InstanceRegisterRequest{ + InstanceRegisterRequest: model.InstanceRegisterRequest{ + Service: serviceInstance.Name + u.Scheme, + ServiceToken: r.opt.ServiceToken, + Namespace: r.opt.Namespace, + Host: host, + Port: portNum, + Protocol: r.opt.Protocol, + Weight: &r.opt.Weight, + Priority: &r.opt.Priority, + Version: &serviceInstance.Version, + Metadata: rmd, + Healthy: &r.opt.Healthy, + Isolate: &r.opt.Isolate, + TTL: &r.opt.TTL, + Timeout: &r.opt.Timeout, + RetryCount: &r.opt.RetryCount, + }, + }) + if err != nil { + return err + } + instanceID := service.InstanceID + + if r.opt.Heartbeat { + // start heartbeat report + go func() { + ticker := time.NewTicker(time.Second * time.Duration(r.opt.TTL)) + defer ticker.Stop() + + for { + <-ticker.C + + err = r.provider.Heartbeat(&api.InstanceHeartbeatRequest{ + InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{ + Service: serviceInstance.Name + u.Scheme, + Namespace: r.opt.Namespace, + Host: host, + Port: portNum, + ServiceToken: r.opt.ServiceToken, + InstanceID: instanceID, + Timeout: &r.opt.Timeout, + RetryCount: &r.opt.RetryCount, + }, + }) + if err != nil { + g.Log().Error(ctx, err.Error()) + continue + } + } + }() + } + + ids = append(ids, instanceID) + } + // need to set InstanceID for Deregister + serviceInstance.ID = strings.Join(ids, _instanceIDSeparator) + return nil +} + +// Deregister the registration. +func (r *Registry) Deregister(ctx context.Context, service *gsvc.Service) error { + split := strings.Split(serviceInstance.ID, _instanceIDSeparator) + for i, endpoint := range serviceInstance.Endpoints { + // get url + u, err := url.Parse(endpoint) + if err != nil { + return err + } + + // get host and port + host, port, err := net.SplitHostPort(u.Host) + if err != nil { + return err + } + + // port to int + portNum, err := strconv.Atoi(port) + if err != nil { + return err + } + // Deregister + err = r.provider.Deregister( + &api.InstanceDeRegisterRequest{ + InstanceDeRegisterRequest: model.InstanceDeRegisterRequest{ + Service: serviceInstance.Name + u.Scheme, + ServiceToken: r.opt.ServiceToken, + Namespace: r.opt.Namespace, + InstanceID: split[i], + Host: host, + Port: portNum, + Timeout: &r.opt.Timeout, + RetryCount: &r.opt.RetryCount, + }, + }, + ) + if err != nil { + return err + } + } + return nil +} + +// Registry returns the service instances in memory according to the service name. +func (r *Registry) Registry(_ context.Context, serviceName string) ([]*gsvc.Service, error) { + // get all instances + instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ + GetAllInstancesRequest: model.GetAllInstancesRequest{ + Service: serviceName, + Namespace: r.opt.Namespace, + Timeout: &r.opt.Timeout, + RetryCount: &r.opt.RetryCount, + }, + }) + if err != nil { + return nil, err + } + + serviceInstances := instancesToServiceInstances(instancesResponse.GetInstances()) + + return serviceInstances, nil +} + +// Watch creates a watcher according to the service name. +func (r *Registry) Watch(ctx context.Context, serviceName string) (gsvc.Watcher, error) { + return newWatcher(ctx, r.opt.Namespace, serviceName, r.consumer) +} + +// Watcher is a service watcher. +type Watcher struct { + ServiceName string + Namespace string + Ctx context.Context + Cancel context.CancelFunc + Channel <-chan model.SubScribeEvent + ServiceInstances []*gsvc.Service +} + +func newWatcher(ctx context.Context, namespace string, serviceName string, consumer api.ConsumerAPI) (*Watcher, error) { + watchServiceResponse, err := consumer.WatchService(&api.WatchServiceRequest{ + WatchServiceRequest: model.WatchServiceRequest{ + Key: model.ServiceKey{ + Namespace: namespace, + Service: serviceName, + }, + }, + }) + if err != nil { + return nil, err + } + + w := &Watcher{ + Namespace: namespace, + ServiceName: serviceName, + Channel: watchServiceResponse.EventChannel, + ServiceInstances: instancesToServiceInstances(watchServiceResponse.GetAllInstancesResp.GetInstances()), + } + w.Ctx, w.Cancel = context.WithCancel(ctx) + return w, nil +} + +// Proceed returns services in the following two cases: +// 1.the first time to watch and the service instance list is not empty. +// 2.any service instance changes found. +// if the above two conditions are not met, it will block until the context deadline is exceeded or canceled +func (w *Watcher) Proceed() ([]*gsvc.Service, error) { + select { + case <-w.Ctx.Done(): + return nil, w.Ctx.Err() + case event := <-w.Channel: + if event.GetSubScribeEventType() == model.EventInstance { + // this always true, but we need to check it to make sure EventType not change + if instanceEvent, ok := event.(*model.InstanceEvent); ok { + // handle DeleteEvent + if instanceEvent.DeleteEvent != nil { + for _, instance := range instanceEvent.DeleteEvent.Instances { + for i, serviceInstance := range w.ServiceInstances { + if serviceInstance.ID == instance.GetId() { + // remove equal + if len(w.ServiceInstances) <= 1 { + w.ServiceInstances = w.ServiceInstances[0:0] + continue + } + w.ServiceInstances = append(w.ServiceInstances[:i], w.ServiceInstances[i+1:]...) + } + } + } + } + // handle UpdateEvent + if instanceEvent.UpdateEvent != nil { + for i, serviceInstance := range w.ServiceInstances { + for _, update := range instanceEvent.UpdateEvent.UpdateList { + if serviceInstance.ID == update.Before.GetId() { + w.ServiceInstances[i] = instanceToServiceInstance(update.After) + } + } + } + } + // handle AddEvent + if instanceEvent.AddEvent != nil { + w.ServiceInstances = append(w.ServiceInstances, instancesToServiceInstances(instanceEvent.AddEvent.Instances)...) + } + } + return w.ServiceInstances, nil + } + } + return w.ServiceInstances, nil +} + +// Close the watcher. +func (w *Watcher) Close() error { + w.Cancel() + return nil +} + +func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service { + serviceInstances := make([]*registry.ServiceInstance, 0, len(instances)) + for _, instance := range instances { + if instance.IsHealthy() { + serviceInstances = append(serviceInstances, instanceToServiceInstance(instance)) + } + } + return serviceInstances +} + +func instanceToServiceInstance(instance model.Instance) *gsvc.Service { + metadata := instance.GetMetadata() + // Usually, it won't fail in kratos if register correctly + kind := "" + if k, ok := metadata["kind"]; ok { + kind = k + } + return ®istry.ServiceInstance{ + ID: instance.GetId(), + Name: instance.GetService(), + Version: metadata["version"], + Metadata: metadata, + Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, instance.GetHost(), instance.GetPort())}, + } +} diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go new file mode 100644 index 00000000000..2d0adc1c7a0 --- /dev/null +++ b/contrib/registry/polaris/registry_test.go @@ -0,0 +1,208 @@ +package polaris + +import ( + "context" + "testing" + "time" + + "github.com/polarismesh/polaris-go/pkg/config" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/os/gctx" +) + +// TestRegistry . TestRegistryManyService +func TestRegistry(t *testing.T) { + conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) + + r := NewRegistryWithConfig( + conf, + WithTimeout(time.Second*10), + WithTTL(100), + ) + + ctx := context.Background() + + svc := &gsvc.Service{ + Name: "kratos-provider-0-", + Version: "test", + Metadata: map[string]string{"app": "kratos"}, + Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + } + + err := r.Register(ctx, svc) + if err != nil { + t.Fatal(err) + } + + err = r.Deregister(ctx, svc) + if err != nil { + t.Fatal(err) + } +} + +// TestRegistryMany . TestRegistryManyService +func TestRegistryMany(t *testing.T) { + conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) + + r := NewRegistryWithConfig( + conf, + WithTimeout(time.Second*10), + WithTTL(100), + ) + + svc := &gsvc.Service{ + Name: "kratos-provider-1-", + Version: "test", + Metadata: map[string]string{"app": "kratos"}, + Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + } + svc1 := &gsvc.Service{ + Name: "kratos-provider-2-", + Version: "test", + Metadata: map[string]string{"app": "kratos"}, + Endpoints: []string{"tcp://127.0.0.1:9001?isSecure=false"}, + } + svc2 := &gsvc.Service{ + Name: "kratos-provider-3-", + Version: "test", + Metadata: map[string]string{"app": "kratos"}, + Endpoints: []string{"tcp://127.0.0.1:9002?isSecure=false"}, + } + + err := r.Register(context.Background(), svc) + if err != nil { + t.Fatal(err) + } + + err = r.Register(context.Background(), svc1) + if err != nil { + t.Fatal(err) + } + + err = r.Register(context.Background(), svc2) + if err != nil { + t.Fatal(err) + } + + err = r.Deregister(context.Background(), svc) + if err != nil { + t.Fatal(err) + } + + err = r.Deregister(context.Background(), svc1) + if err != nil { + t.Fatal(err) + } + + err = r.Deregister(context.Background(), svc2) + if err != nil { + t.Fatal(err) + } +} + +// TestGetService . TestGetService +func TestGetService(t *testing.T) { + conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) + + r := NewRegistryWithConfig( + conf, + WithTimeout(time.Second*10), + WithTTL(100), + ) + + ctx := context.Background() + + svc := &gsvc.Service{ + Name: "kratos-provider-4-", + Version: "test", + Metadata: map[string]string{"app": "kratos"}, + Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + } + + err := r.Register(ctx, svc) + if err != nil { + t.Fatal(err) + } + time.Sleep(time.Second * 1) + serviceInstances, err := r.GetService(ctx, "kratos-provider-4-tcp") + if err != nil { + t.Fatal(err) + } + for _, instance := range serviceInstances { + g.Log().Info(ctx, instance) + } + + err = r.Deregister(ctx, svc) + if err != nil { + t.Fatal(err) + } +} + +// TestWatch . TestWatch +func TestWatch(t *testing.T) { + conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) + + r := NewRegistryWithConfig( + conf, + WithTimeout(time.Second*10), + WithTTL(100), + ) + + ctx := gctx.New() + + svc := ®istry.ServiceInstance{ + Name: "kratos-provider-4-", + Version: "test", + Metadata: map[string]string{"app": "kratos"}, + Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + } + + watch, err := r.Watch(context.Background(), "kratos-provider-4-tcp") + if err != nil { + t.Fatal(err) + } + + err = r.Register(context.Background(), svc) + if err != nil { + t.Fatal(err) + } + // watch svc + time.Sleep(time.Second * 1) + + // svc register, AddEvent + next, err := watch.Next() + if err != nil { + t.Fatal(err) + } + for _, instance := range next { + // it will output one instance + g.Log().Info(ctx, instance) + } + + err = r.Deregister(context.Background(), svc) + if err != nil { + t.Fatal(err) + } + + // svc deregister, DeleteEvent + next, err = watch.Next() + if err != nil { + t.Fatal(err) + } + for _, instance := range next { + // it will output nothing + g.Log().Info(ctx, instance) + } + + err = watch.Close() + if err != nil { + t.Fatal(err) + } + _, err = watch.Next() + if err == nil { + // if nil, stop failed + t.Fatal() + } +} From 1219bd93bf4c85fb11217a49fc872ba59c65e632 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 20 Apr 2022 22:54:11 +0800 Subject: [PATCH 04/70] up --- contrib/registry/polaris/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/registry/polaris/go.mod b/contrib/registry/polaris/go.mod index ae0009fd7db..39abf345544 100644 --- a/contrib/registry/polaris/go.mod +++ b/contrib/registry/polaris/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/polaris/v2 go 1.16 require ( - github.com/gogf/gf/v2 v2.0.6 + github.com/gogf/gf/v2 v2.0.0 github.com/polarismesh/polaris-go v1.0.2 ) From 2495e8bb73d76ad7797dc7d33e7175bd84c1f33c Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 3 May 2022 16:26:25 +0800 Subject: [PATCH 05/70] feat: upgrade dependent package version --- contrib/registry/polaris/go.mod | 4 +-- contrib/registry/polaris/go.sum | 2 ++ go.mod | 11 ++++--- go.sum | 56 ++++++++++++++++++++++----------- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/contrib/registry/polaris/go.mod b/contrib/registry/polaris/go.mod index 39abf345544..a7e170d3f8f 100644 --- a/contrib/registry/polaris/go.mod +++ b/contrib/registry/polaris/go.mod @@ -1,10 +1,10 @@ module github.com/gogf/gf/contrib/registry/polaris/v2 -go 1.16 +go 1.15 require ( github.com/gogf/gf/v2 v2.0.0 - github.com/polarismesh/polaris-go v1.0.2 + github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b ) replace github.com/gogf/gf/v2 => ../../../ diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum index a2361b12cb5..e7edd8089e2 100644 --- a/contrib/registry/polaris/go.sum +++ b/contrib/registry/polaris/go.sum @@ -134,6 +134,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/polarismesh/polaris-go v1.0.2 h1:vMPTgO+DKNq9mC5HP7wFnlotIqg2waOAIKQq0qoZchY= github.com/polarismesh/polaris-go v1.0.2/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= +github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b h1:BFQejYBpde/ryb69+IDd8dsew7Y8z59mTFzDv8hMqX4= +github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= diff --git a/go.mod b/go.mod index 383d8496e19..cf7da42f7ef 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,11 @@ module github.com/gogf/gf/v2 go 1.15 require ( - github.com/BurntSushi/toml v0.4.1 + github.com/BurntSushi/toml v1.1.0 github.com/clbanning/mxj/v2 v2.5.5 github.com/fatih/color v1.13.0 - github.com/fsnotify/fsnotify v1.5.1 - github.com/go-redis/redis/v8 v8.11.4 + github.com/fsnotify/fsnotify v1.5.4 + github.com/go-redis/redis/v8 v8.11.5 github.com/go-sql-driver/mysql v1.6.0 github.com/gorilla/websocket v1.5.0 github.com/grokify/html-strip-tags-go v0.0.1 @@ -16,7 +16,8 @@ require ( go.opentelemetry.io/otel v1.0.0 go.opentelemetry.io/otel/sdk v1.0.0 go.opentelemetry.io/otel/trace v1.0.0 - golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 - golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 + golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 + golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba // indirect + golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) diff --git a/go.sum b/go.sum index afcaa4dd5db..f99cb621ff4 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,10 @@ -github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= -github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E= github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -13,10 +16,10 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= -github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= -github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= -github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= +github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= @@ -38,11 +41,13 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/longbridgeapp/sqlparser v0.3.1 h1:iWOZWGIFgQrJRgobLXUNJdvqGRpbVXkyKUKUA5CNJBE= github.com/longbridgeapp/sqlparser v0.3.1/go.mod h1:GIHaUq8zvYyHLCLMJJykx1CdM6LHtkUih/QaJXySSx4= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= @@ -59,12 +64,16 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= -github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= 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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -72,7 +81,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -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.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= go.opentelemetry.io/otel/sdk v1.0.0 h1:BNPMYUONPNbLneMttKSjQhOTlFLOD9U22HNG1KrIN2Y= @@ -82,17 +91,19 @@ go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH81 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -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/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -103,6 +114,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -111,19 +123,25 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw= +golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= -golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 h1:dejsXyH3RsgJiGtZB8yNSjsPzZU/hAJ8aMJmRi7+Dtk= +golang.org/x/text v0.3.8-0.20220428233042-78819d01d041/go.mod h1:UqJy94PED2GK2o3pz2dHDKz1s05DEJMG9tubaZ3t0uI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= 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= From 2b35d06d7c1899da1dd199b694a43e7ef8f6f847 Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 3 May 2022 19:22:14 +0800 Subject: [PATCH 06/70] action --- .github/workflows/gf.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/gf.yml b/.github/workflows/gf.yml index 50f573870a5..41c15474f56 100644 --- a/.github/workflows/gf.yml +++ b/.github/workflows/gf.yml @@ -6,10 +6,12 @@ on: branches: - master - develop + - feature/ pull_request: branches: - master - develop + - feature/ env: From bfa829e6479ef1df233f5079fc6a6f0b78debf55 Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 3 May 2022 19:24:11 +0800 Subject: [PATCH 07/70] fix --- .github/workflows/gf.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gf.yml b/.github/workflows/gf.yml index 41c15474f56..b47020f6ca4 100644 --- a/.github/workflows/gf.yml +++ b/.github/workflows/gf.yml @@ -6,12 +6,12 @@ on: branches: - master - develop - - feature/ + - feature/polaris pull_request: branches: - master - develop - - feature/ + - feature/polaris env: From 8181cf107bc211cf77edcb4edbb2f648021948dd Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 3 May 2022 21:23:20 +0800 Subject: [PATCH 08/70] improve code --- .../registry/polaris/{polaris.go => doc.go} | 0 contrib/registry/polaris/registry.go | 31 +++++------ contrib/registry/polaris/registry_test.go | 42 +++++++-------- net/gsvc/gsvc_service.go | 54 ++++++++++++------- text/gstr/gstr_convert.go | 11 ++-- text/gstr/gstr_slashes.go | 3 +- text/gstr/gstr_split_join.go | 3 +- text/gstr/gstr_upper_lower.go | 5 +- 8 files changed, 84 insertions(+), 65 deletions(-) rename contrib/registry/polaris/{polaris.go => doc.go} (100%) diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/doc.go similarity index 100% rename from contrib/registry/polaris/polaris.go rename to contrib/registry/polaris/doc.go diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index b1b5cd4742d..9f226c59689 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -15,6 +15,7 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/util/gconv" ) var ( @@ -120,6 +121,7 @@ func WithHeartbeat(heartbeat bool) Option { return func(o *options) { o.Heartbeat = heartbeat } } +// NewRegistry 创建一个注册服务 func NewRegistry(provider api.ProviderAPI, consumer api.ConsumerAPI, opts ...Option) (r *Registry) { op := options{ Namespace: "default", @@ -158,7 +160,7 @@ func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Regist } // Register the registration. -func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { +func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) error { ids := make([]string, 0, len(serviceInstance.Endpoints)) for _, endpoint := range serviceInstance.Endpoints { // get url @@ -180,14 +182,14 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { } // medata - var rmd map[string]string + var rmd map[string]interface{} if serviceInstance.Metadata == nil { - rmd = map[string]string{ + rmd = map[string]interface{}{ "kind": u.Scheme, "version": serviceInstance.Version, } } else { - rmd = make(map[string]string, len(serviceInstance.Metadata)+2) + rmd = make(map[string]interface{}, len(serviceInstance.Metadata)+2) for k, v := range serviceInstance.Metadata { rmd[k] = v } @@ -207,7 +209,7 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { Weight: &r.opt.Weight, Priority: &r.opt.Priority, Version: &serviceInstance.Version, - Metadata: rmd, + Metadata: gconv.MapStrStr(rmd), Healthy: &r.opt.Healthy, Isolate: &r.opt.Isolate, TTL: &r.opt.TTL, @@ -252,13 +254,13 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { ids = append(ids, instanceID) } // need to set InstanceID for Deregister - serviceInstance.ID = strings.Join(ids, _instanceIDSeparator) + // serviceInstance.ID = strings.Join(ids, _instanceIDSeparator) return nil } // Deregister the registration. -func (r *Registry) Deregister(ctx context.Context, service *gsvc.Service) error { - split := strings.Split(serviceInstance.ID, _instanceIDSeparator) +func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service) error { + split := strings.Split(serviceInstance.Key(), _instanceIDSeparator) for i, endpoint := range serviceInstance.Endpoints { // get url u, err := url.Parse(endpoint) @@ -367,13 +369,13 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) { return nil, w.Ctx.Err() case event := <-w.Channel: if event.GetSubScribeEventType() == model.EventInstance { - // this always true, but we need to check it to make sure EventType not change + // these are always true, but we need to check it to make sure EventType not change if instanceEvent, ok := event.(*model.InstanceEvent); ok { // handle DeleteEvent if instanceEvent.DeleteEvent != nil { for _, instance := range instanceEvent.DeleteEvent.Instances { for i, serviceInstance := range w.ServiceInstances { - if serviceInstance.ID == instance.GetId() { + if serviceInstance.Key() == instance.GetId() { // remove equal if len(w.ServiceInstances) <= 1 { w.ServiceInstances = w.ServiceInstances[0:0] @@ -388,7 +390,7 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) { if instanceEvent.UpdateEvent != nil { for i, serviceInstance := range w.ServiceInstances { for _, update := range instanceEvent.UpdateEvent.UpdateList { - if serviceInstance.ID == update.Before.GetId() { + if serviceInstance.Key() == update.Before.GetId() { w.ServiceInstances[i] = instanceToServiceInstance(update.After) } } @@ -412,7 +414,7 @@ func (w *Watcher) Close() error { } func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service { - serviceInstances := make([]*registry.ServiceInstance, 0, len(instances)) + serviceInstances := make([]*gsvc.Service, 0, len(instances)) for _, instance := range instances { if instance.IsHealthy() { serviceInstances = append(serviceInstances, instanceToServiceInstance(instance)) @@ -428,11 +430,10 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { if k, ok := metadata["kind"]; ok { kind = k } - return ®istry.ServiceInstance{ - ID: instance.GetId(), + return &gsvc.Service{ Name: instance.GetService(), Version: metadata["version"], - Metadata: metadata, + Metadata: gconv.Map(metadata), Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, instance.GetHost(), instance.GetPort())}, } } diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index 2d0adc1c7a0..08b8d6c68f3 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -12,7 +12,7 @@ import ( "github.com/gogf/gf/v2/os/gctx" ) -// TestRegistry . TestRegistryManyService +// TestRegistry TestRegistryManyService func TestRegistry(t *testing.T) { conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) @@ -25,9 +25,9 @@ func TestRegistry(t *testing.T) { ctx := context.Background() svc := &gsvc.Service{ - Name: "kratos-provider-0-", + Name: "goframe-provider-0-", Version: "test", - Metadata: map[string]string{"app": "kratos"}, + Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, } @@ -53,21 +53,21 @@ func TestRegistryMany(t *testing.T) { ) svc := &gsvc.Service{ - Name: "kratos-provider-1-", + Name: "goframe-provider-1-", Version: "test", - Metadata: map[string]string{"app": "kratos"}, + Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, } svc1 := &gsvc.Service{ - Name: "kratos-provider-2-", + Name: "goframe-provider-2-", Version: "test", - Metadata: map[string]string{"app": "kratos"}, + Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9001?isSecure=false"}, } svc2 := &gsvc.Service{ - Name: "kratos-provider-3-", + Name: "goframe-provider-3-", Version: "test", - Metadata: map[string]string{"app": "kratos"}, + Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9002?isSecure=false"}, } @@ -102,7 +102,7 @@ func TestRegistryMany(t *testing.T) { } } -// TestGetService . TestGetService +// TestGetService Test GetService func TestGetService(t *testing.T) { conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) @@ -115,9 +115,9 @@ func TestGetService(t *testing.T) { ctx := context.Background() svc := &gsvc.Service{ - Name: "kratos-provider-4-", + Name: "goframe-provider-4-", Version: "test", - Metadata: map[string]string{"app": "kratos"}, + Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, } @@ -126,7 +126,7 @@ func TestGetService(t *testing.T) { t.Fatal(err) } time.Sleep(time.Second * 1) - serviceInstances, err := r.GetService(ctx, "kratos-provider-4-tcp") + serviceInstances, err := r.Registry(ctx, "goframe-provider-4-tcp") if err != nil { t.Fatal(err) } @@ -140,7 +140,7 @@ func TestGetService(t *testing.T) { } } -// TestWatch . TestWatch +// TestWatch Test Watch func TestWatch(t *testing.T) { conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) @@ -152,14 +152,14 @@ func TestWatch(t *testing.T) { ctx := gctx.New() - svc := ®istry.ServiceInstance{ - Name: "kratos-provider-4-", + svc := &gsvc.Service{ + Name: "goframe-provider-4-", Version: "test", - Metadata: map[string]string{"app": "kratos"}, + Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, } - watch, err := r.Watch(context.Background(), "kratos-provider-4-tcp") + watch, err := r.Watch(context.Background(), "goframe-provider-4-tcp") if err != nil { t.Fatal(err) } @@ -172,7 +172,7 @@ func TestWatch(t *testing.T) { time.Sleep(time.Second * 1) // svc register, AddEvent - next, err := watch.Next() + next, err := watch.Proceed() if err != nil { t.Fatal(err) } @@ -187,7 +187,7 @@ func TestWatch(t *testing.T) { } // svc deregister, DeleteEvent - next, err = watch.Next() + next, err = watch.Proceed() if err != nil { t.Fatal(err) } @@ -200,7 +200,7 @@ func TestWatch(t *testing.T) { if err != nil { t.Fatal(err) } - _, err = watch.Next() + _, err = watch.Proceed() if err == nil { // if nil, stop failed t.Fatal() diff --git a/net/gsvc/gsvc_service.go b/net/gsvc/gsvc_service.go index f8e0db3e6c2..64de6c4b05b 100644 --- a/net/gsvc/gsvc_service.go +++ b/net/gsvc/gsvc_service.go @@ -20,6 +20,15 @@ import ( const ( separator = "/" + delimiter = "," + + zero = iota + one + two + three + four + five + six ) // NewServiceWithName creates and returns service from `name`. @@ -29,37 +38,44 @@ func NewServiceWithName(name string) (s *Service) { Metadata: make(Metadata), } s.autoFillDefaultAttributes() - return s + + return } // NewServiceWithKV creates and returns service from `key` and `value`. func NewServiceWithKV(key, value []byte) (s *Service, err error) { array := gstr.Split(gstr.Trim(string(key), separator), separator) - if len(array) < 6 { - return nil, gerror.NewCodef(gcode.CodeInvalidParameter, `invalid service key "%s"`, key) + if len(array) < six { + err = gerror.NewCodef(gcode.CodeInvalidParameter, `invalid service key "%s"`, key) + + return } s = &Service{ - Prefix: array[0], - Deployment: array[1], - Namespace: array[2], - Name: array[3], - Version: array[4], - Endpoints: gstr.Split(array[5], ","), + Prefix: array[zero], + Deployment: array[one], + Namespace: array[two], + Name: array[three], + Version: array[four], + Endpoints: gstr.Split(array[five], delimiter), Metadata: make(Metadata), } s.autoFillDefaultAttributes() - if len(value) > 0 { + if len(value) > zero { if err = gjson.Unmarshal(value, &s.Metadata); err != nil { - return nil, gerror.WrapCodef(gcode.CodeInvalidParameter, err, `invalid service value "%s"`, value) + err = gerror.WrapCodef(gcode.CodeInvalidParameter, err, `invalid service value "%s"`, value) + + return nil, err } } + return s, nil } -// Key formats the service information and returns the Service as registering key. +// Key formats the service information and return the Service as registering key. func (s *Service) Key() string { serviceNameUnique := s.KeyWithoutEndpoints() serviceNameUnique += separator + gstr.Join(s.Endpoints, ",") + return serviceNameUnique } @@ -68,23 +84,20 @@ func (s *Service) KeyWithSchema() string { return fmt.Sprintf(`%s://%s`, Schema, s.Key()) } -// KeyWithoutEndpoints formats the service information and returns a string as unique name of service. +// KeyWithoutEndpoints formats the service information and returns a string as a unique name of service. func (s *Service) KeyWithoutEndpoints() string { s.autoFillDefaultAttributes() - return "/" + gstr.Join([]string{ - s.Prefix, - s.Deployment, - s.Namespace, - s.Name, - s.Version, - }, separator) + + return "/" + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator) } +// Value formats the service information and returns the Service as registering value. func (s *Service) Value() string { b, err := gjson.Marshal(s.Metadata) if err != nil { intlog.Errorf(context.TODO(), `%+v`, err) } + return string(b) } @@ -94,6 +107,7 @@ func (s *Service) Address() string { if len(s.Endpoints) == 0 { return "" } + return s.Endpoints[0] } diff --git a/text/gstr/gstr_convert.go b/text/gstr/gstr_convert.go index 7c4a6add333..13e9760d6d9 100644 --- a/text/gstr/gstr_convert.go +++ b/text/gstr/gstr_convert.go @@ -9,12 +9,13 @@ package gstr import ( "bytes" "fmt" - "github.com/gogf/gf/v2/util/grand" "math" "regexp" "strconv" "strings" "unicode" + + "github.com/gogf/gf/v2/util/grand" ) // Chr return the ascii string of a number(0-255). @@ -27,14 +28,12 @@ func Ord(char string) int { return int(char[0]) } -var ( - // octReg is the regular expression object for checks octal string. - octReg = regexp.MustCompile(`\\[0-7]{3}`) -) +// octReg is the regular expression object for checks octal string. +var octReg = regexp.MustCompile(`\\[0-7]{3}`) // OctStr converts string container octal string to its original string, // for example, to Chinese string. -// Eg: `\346\200\241` -> 怡 +// Eg: `\346\200\241` -> 怡. func OctStr(str string) string { return octReg.ReplaceAllStringFunc( str, diff --git a/text/gstr/gstr_slashes.go b/text/gstr/gstr_slashes.go index e897673ba2d..1173047f7d7 100644 --- a/text/gstr/gstr_slashes.go +++ b/text/gstr/gstr_slashes.go @@ -8,6 +8,7 @@ package gstr import ( "bytes" + "github.com/gogf/gf/v2/internal/utils" ) @@ -30,7 +31,7 @@ func StripSlashes(str string) string { } // QuoteMeta returns a version of str with a backslash character (\) -// before every character that is among: .\+*?[^]($) +// before every character that is among: .\+*?[^]($). func QuoteMeta(str string, chars ...string) string { var buf bytes.Buffer for _, char := range str { diff --git a/text/gstr/gstr_split_join.go b/text/gstr/gstr_split_join.go index 737f85c21a5..8858cacf573 100644 --- a/text/gstr/gstr_split_join.go +++ b/text/gstr/gstr_split_join.go @@ -7,9 +7,10 @@ package gstr import ( + "strings" + "github.com/gogf/gf/v2/internal/utils" "github.com/gogf/gf/v2/util/gconv" - "strings" ) // Split splits string `str` by a string `delimiter`, to an array. diff --git a/text/gstr/gstr_upper_lower.go b/text/gstr/gstr_upper_lower.go index 3d6c75ad90b..1301b82493d 100644 --- a/text/gstr/gstr_upper_lower.go +++ b/text/gstr/gstr_upper_lower.go @@ -7,8 +7,11 @@ package gstr import ( - "github.com/gogf/gf/v2/internal/utils" "strings" + + "strings" + + "github.com/gogf/gf/v2/internal/utils" ) // ToLower returns a copy of the string s with all Unicode letters mapped to their lower case. From 582120f361e34c210e72841bdbf7cdd96658fdab Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 3 May 2022 22:19:12 +0800 Subject: [PATCH 09/70] feat: New ID ID is the unique instance ID as registered. --- contrib/registry/polaris/registry.go | 8 ++++---- net/gsvc/gsvc.go | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index 9f226c59689..34a708fa7a2 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -254,7 +254,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) ids = append(ids, instanceID) } // need to set InstanceID for Deregister - // serviceInstance.ID = strings.Join(ids, _instanceIDSeparator) + serviceInstance.ID = strings.Join(ids, _instanceIDSeparator) return nil } @@ -375,7 +375,7 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) { if instanceEvent.DeleteEvent != nil { for _, instance := range instanceEvent.DeleteEvent.Instances { for i, serviceInstance := range w.ServiceInstances { - if serviceInstance.Key() == instance.GetId() { + if serviceInstance.ID == instance.GetId() { // remove equal if len(w.ServiceInstances) <= 1 { w.ServiceInstances = w.ServiceInstances[0:0] @@ -390,7 +390,7 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) { if instanceEvent.UpdateEvent != nil { for i, serviceInstance := range w.ServiceInstances { for _, update := range instanceEvent.UpdateEvent.UpdateList { - if serviceInstance.Key() == update.Before.GetId() { + if serviceInstance.ID == update.Before.GetId() { w.ServiceInstances[i] = instanceToServiceInstance(update.After) } } @@ -425,7 +425,7 @@ func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service { func instanceToServiceInstance(instance model.Instance) *gsvc.Service { metadata := instance.GetMetadata() - // Usually, it won't fail in kratos if register correctly + // Usually, it won't fail in goframe if register correctly kind := "" if k, ok := metadata["kind"]; ok { kind = k diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index da86aaf440e..3d26ad840ed 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -25,7 +25,7 @@ type Registrar interface { // Register registers `service` to Registry. Register(ctx context.Context, service *Service) error - // Deregister off-lines and removes `service` from Registry. + // Deregister off-lines and removes `service` from the Registry. Deregister(ctx context.Context, service *Service) error } @@ -49,9 +49,10 @@ type Watcher interface { // Service definition. type Service struct { + ID string // ID is the unique instance ID as registered. Prefix string // Service prefix. Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. - Namespace string // Service Namespace, to indicate different service in the same environment with the same Name. + Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. Name string // Name for the service. Version string // Service version, eg: v1.0.0, v2.1.1, etc. Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. @@ -63,18 +64,20 @@ type Metadata map[string]interface{} // SearchInput is the input for service searching. type SearchInput struct { + ID string // ID is the unique instance ID as registered. Prefix string // Service prefix. Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. - Namespace string // Service Namespace, to indicate different service in the same environment with the same Name. + Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. Name string // Name for the service. Version string // Service version, eg: v1.0.0, v2.1.1, etc.} } // WatchInput is the input for service watching. type WatchInput struct { + ID string // ID is the unique instance ID as registered. Prefix string // Service prefix. Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. - Namespace string // Service Namespace, to indicate different service in the same environment with the same Name. + Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. Name string // Name for the service. Version string // Service version, eg: v1.0.0, v2.1.1, etc.} } @@ -111,5 +114,6 @@ func SetRegistry(registry Registry) { // GetRegistry returns the default Registry that is previously set. // It returns nil if no Registry is set. func GetRegistry() Registry { + return defaultRegistry } From 3c9ac202557b920d91f1be98716522948801909e Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 3 May 2022 22:28:17 +0800 Subject: [PATCH 10/70] fix: Remove repeatedly introduced packages --- contrib/registry/polaris/doc.go | 7 +++++++ contrib/registry/polaris/registry.go | 6 ++++++ contrib/registry/polaris/registry_test.go | 6 ++++++ text/gstr/gstr_upper_lower.go | 2 -- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/contrib/registry/polaris/doc.go b/contrib/registry/polaris/doc.go index 9bcac4ada3b..9ffc871b00c 100644 --- a/contrib/registry/polaris/doc.go +++ b/contrib/registry/polaris/doc.go @@ -1 +1,8 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +// Package polaris implements service Registry and Discovery using polaris. package polaris diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index 34a708fa7a2..943a29297c6 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -1,3 +1,9 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + package polaris import ( diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index 08b8d6c68f3..7b0f64e54b7 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -1,3 +1,9 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + package polaris import ( diff --git a/text/gstr/gstr_upper_lower.go b/text/gstr/gstr_upper_lower.go index 1301b82493d..69ad78c11d5 100644 --- a/text/gstr/gstr_upper_lower.go +++ b/text/gstr/gstr_upper_lower.go @@ -9,8 +9,6 @@ package gstr import ( "strings" - "strings" - "github.com/gogf/gf/v2/internal/utils" ) From 9b481bd172ff4ba73c978d1207ed2e110ef91595 Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 3 May 2022 22:40:37 +0800 Subject: [PATCH 11/70] feat: Add Polaris service --- .github/workflows/gf.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gf.yml b/.github/workflows/gf.yml index b47020f6ca4..aafe11cdaef 100644 --- a/.github/workflows/gf.yml +++ b/.github/workflows/gf.yml @@ -84,7 +84,11 @@ jobs: - 9000:9000 - 8123:8123 - 9001:9001 - + polaris: + image: huyuanxin/polaris-server-with-config:latest + ports: + - 8090:8090 + - 8091:8091 # strategy set strategy: From 68c49d7e8ad1dbed1ba2842e437e9736e38d23b3 Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 3 May 2022 23:17:56 +0800 Subject: [PATCH 12/70] feat: improve --- contrib/registry/polaris/go.sum | 60 ++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum index e7edd8089e2..903ca886bae 100644 --- a/contrib/registry/polaris/go.sum +++ b/contrib/registry/polaris/go.sum @@ -1,8 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= -github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -12,6 +12,9 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E= github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -36,12 +39,12 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= -github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= +github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= -github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= @@ -78,6 +81,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -93,6 +97,7 @@ github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -122,18 +127,20 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= -github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.0.2 h1:vMPTgO+DKNq9mC5HP7wFnlotIqg2waOAIKQq0qoZchY= -github.com/polarismesh/polaris-go v1.0.2/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b h1:BFQejYBpde/ryb69+IDd8dsew7Y8z59mTFzDv8hMqX4= github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -151,7 +158,7 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 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.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= go.opentelemetry.io/otel/sdk v1.0.0 h1:BNPMYUONPNbLneMttKSjQhOTlFLOD9U22HNG1KrIN2Y= @@ -170,13 +177,17 @@ go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 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.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= 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= @@ -188,12 +199,13 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -209,6 +221,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -219,15 +232,21 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw= +golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= -golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 h1:dejsXyH3RsgJiGtZB8yNSjsPzZU/hAJ8aMJmRi7+Dtk= +golang.org/x/text v0.3.8-0.20220428233042-78819d01d041/go.mod h1:UqJy94PED2GK2o3pz2dHDKz1s05DEJMG9tubaZ3t0uI= 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= @@ -237,7 +256,8 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= +golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= 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= From 02ca024375875397cad26ee12b66f4812e782112 Mon Sep 17 00:00:00 2001 From: John Guo Date: Fri, 6 May 2022 20:25:21 +0800 Subject: [PATCH 13/70] improve package ghttp --- net/ghttp/ghttp.go | 40 +++++++++------------ net/ghttp/ghttp_server.go | 12 +++---- net/ghttp/ghttp_server_router.go | 26 ++++++-------- net/ghttp/ghttp_server_router_hook.go | 2 +- net/ghttp/ghttp_server_router_middleware.go | 4 +-- net/ghttp/ghttp_server_router_serve.go | 10 +++--- net/ghttp/ghttp_server_service_handler.go | 4 +-- net/ghttp/ghttp_server_service_object.go | 14 ++++---- 8 files changed, 51 insertions(+), 61 deletions(-) diff --git a/net/ghttp/ghttp.go b/net/ghttp/ghttp.go index 115c6dcb8c1..e29bfed3d20 100644 --- a/net/ghttp/ghttp.go +++ b/net/ghttp/ghttp.go @@ -25,19 +25,19 @@ import ( type ( // Server wraps the http.Server and provides more rich features. Server struct { - instance string // Instance name. - config ServerConfig // Configuration. - plugins []Plugin // Plugin array to extend server functionality. - servers []*gracefulServer // Underlying http.Server array. - serverCount *gtype.Int // Underlying http.Server count. - closeChan chan struct{} // Used for underlying server closing event notification. - serveTree map[string]interface{} // The route maps tree. - serveCache *gcache.Cache // Server caches for internal usage. - routesMap map[string][]registeredRouteItem // Route map mainly for route dumps and repeated route checks. - statusHandlerMap map[string][]HandlerFunc // Custom status handler map. - sessionManager *gsession.Manager // Session manager. - openapi *goai.OpenApiV3 // The OpenApi specification management object. - service *gsvc.Service // The service for Registry. + instance string // Instance name of current HTTP server. + config ServerConfig // Server configuration. + plugins []Plugin // Plugin array to extend server functionality. + servers []*gracefulServer // Underlying http.Server array. + serverCount *gtype.Int // Underlying http.Server number for internal usage. + closeChan chan struct{} // Used for underlying server closing event notification. + serveTree map[string]interface{} // The route maps tree. + serveCache *gcache.Cache // Server caches for internal usage. + routesMap map[string][]*HandlerItem // Route map mainly for route dumps and repeated route checks. + statusHandlerMap map[string][]HandlerFunc // Custom status handler map. + sessionManager *gsession.Manager // Session manager. + openapi *goai.OpenApiV3 // The OpenApi specification management object. + service *gsvc.Service // The service for Registry. } // Router object. @@ -52,7 +52,7 @@ type ( // RouterItem is just for route dumps. RouterItem struct { - Handler *handlerItem // The handler. + Handler *HandlerItem // The handler. Server string // Server name. Address string // Listening address. Domain string // Bound domain. @@ -74,9 +74,9 @@ type ( Value reflect.Value // Reflect value information for current handler, which is used for extensions of the handler feature. } - // handlerItem is the registered handler for route handling, + // HandlerItem is the registered handler for route handling, // including middleware and hook functions. - handlerItem struct { + HandlerItem struct { Id int // Unique handler item id mark. Name string // Handler name, which is automatically retrieved from runtime stack when registered. Type string // Handler type: object/handler/middleware/hook. @@ -91,16 +91,10 @@ type ( // handlerParsedItem is the item parsed from URL.Path. handlerParsedItem struct { - Handler *handlerItem // Handler information. + Handler *HandlerItem // Handler information. Values map[string]string // Router values parsed from URL.Path. } - // registeredRouteItem stores the information of the router and is used for route map. - registeredRouteItem struct { - Source string // Source file path and its line number. - Handler *handlerItem // Handler object. - } - // Listening file descriptor mapping. // The key is either "http" or "https" and the value is its FD. listenerFdMap = map[string]string diff --git a/net/ghttp/ghttp_server.go b/net/ghttp/ghttp_server.go index 1bbd5731f32..3dd2500c77e 100644 --- a/net/ghttp/ghttp_server.go +++ b/net/ghttp/ghttp_server.go @@ -104,7 +104,7 @@ func GetServer(name ...interface{}) *Server { statusHandlerMap: make(map[string][]HandlerFunc), serveTree: make(map[string]interface{}), serveCache: gcache.New(), - routesMap: make(map[string][]registeredRouteItem), + routesMap: make(map[string][]*HandlerItem), openapi: goai.New(), } // Initialize the server using default configurations. @@ -345,19 +345,19 @@ func (s *Server) GetRoutes() []RouterItem { } address += "tls" + s.config.HTTPSAddr } - for k, registeredItems := range s.routesMap { + for k, handlerItems := range s.routesMap { array, _ := gregex.MatchString(`(.*?)%([A-Z]+):(.+)@(.+)`, k) - for index, registeredItem := range registeredItems { + for index, handlerItem := range handlerItems { item := RouterItem{ Server: s.config.Name, Address: address, Domain: array[4], - Type: registeredItem.Handler.Type, + Type: handlerItem.Type, Middleware: array[1], Method: array[2], Route: array[3], - Priority: len(registeredItems) - index - 1, - Handler: registeredItem.Handler, + Priority: len(handlerItems) - index - 1, + Handler: handlerItem, } switch item.Handler.Type { case HandlerTypeObject, HandlerTypeHandler: diff --git a/net/ghttp/ghttp_server_router.go b/net/ghttp/ghttp_server_router.go index 5f4a24daeac..973ac35a854 100644 --- a/net/ghttp/ghttp_server_router.go +++ b/net/ghttp/ghttp_server_router.go @@ -70,7 +70,7 @@ func (s *Server) parsePattern(pattern string) (domain, method, path string, err type setHandlerInput struct { Prefix string Pattern string - HandlerItem *handlerItem + HandlerItem *HandlerItem } // setHandler creates router item with a given handler and pattern and registers the handler to the router tree. @@ -131,11 +131,11 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { switch handler.Type { case HandlerTypeHandler, HandlerTypeObject: if items, ok := s.routesMap[routerKey]; ok { - var duplicatedHandler *handlerItem - for _, item := range items { - switch item.Handler.Type { + var duplicatedHandler *HandlerItem + for i, item := range items { + switch item.Type { case HandlerTypeHandler, HandlerTypeObject: - duplicatedHandler = item.Handler + duplicatedHandler = items[i] break } } @@ -225,11 +225,11 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { } // It iterates the list array of `lists`, compares priorities and inserts the new router item in // the proper position of each list. The priority of the list is ordered from high to low. - var item *handlerItem + var item *HandlerItem for _, l := range lists { pushed := false for e := l.Front(); e != nil; e = e.Next() { - item = e.Value.(*handlerItem) + item = e.Value.(*HandlerItem) // Checks the priority whether inserting the route item before current item, // which means it has higher priority. if s.compareRouterPriority(handler, item) { @@ -246,20 +246,16 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { } // Initialize the route map item. if _, ok := s.routesMap[routerKey]; !ok { - s.routesMap[routerKey] = make([]registeredRouteItem, 0) + s.routesMap[routerKey] = make([]*HandlerItem, 0) } - var routeItem = registeredRouteItem{ - Source: handler.Source, - Handler: handler, - } switch handler.Type { case HandlerTypeHandler, HandlerTypeObject: // Overwrite the route. - s.routesMap[routerKey] = []registeredRouteItem{routeItem} + s.routesMap[routerKey] = []*HandlerItem{handler} default: // Append the route. - s.routesMap[routerKey] = append(s.routesMap[routerKey], routeItem) + s.routesMap[routerKey] = append(s.routesMap[routerKey], handler) } } @@ -271,7 +267,7 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { // 1. The middleware has the most high priority. // 2. URI: The deeper, the higher (simply check the count of char '/' in the URI). // 3. Route type: {xxx} > :xxx > *xxx. -func (s *Server) compareRouterPriority(newItem *handlerItem, oldItem *handlerItem) bool { +func (s *Server) compareRouterPriority(newItem *HandlerItem, oldItem *HandlerItem) bool { // If they're all types of middleware, the priority is according to their registered sequence. if newItem.Type == HandlerTypeMiddleware && oldItem.Type == HandlerTypeMiddleware { return false diff --git a/net/ghttp/ghttp_server_router_hook.go b/net/ghttp/ghttp_server_router_hook.go index c5f6f255a1f..9c1112bee46 100644 --- a/net/ghttp/ghttp_server_router_hook.go +++ b/net/ghttp/ghttp_server_router_hook.go @@ -41,7 +41,7 @@ func (s *Server) doBindHookHandler(ctx context.Context, in doBindHookHandlerInpu setHandlerInput{ Prefix: in.Prefix, Pattern: in.Pattern, - HandlerItem: &handlerItem{ + HandlerItem: &HandlerItem{ Type: HandlerTypeHook, Name: gdebug.FuncPath(in.Handler), Info: handlerFuncInfo{ diff --git a/net/ghttp/ghttp_server_router_middleware.go b/net/ghttp/ghttp_server_router_middleware.go index d34391a3884..cf4adfc9deb 100644 --- a/net/ghttp/ghttp_server_router_middleware.go +++ b/net/ghttp/ghttp_server_router_middleware.go @@ -30,7 +30,7 @@ func (s *Server) BindMiddleware(pattern string, handlers ...HandlerFunc) { s.setHandler(ctx, setHandlerInput{ Prefix: "", Pattern: pattern, - HandlerItem: &handlerItem{ + HandlerItem: &HandlerItem{ Type: HandlerTypeMiddleware, Name: gdebug.FuncPath(handler), Info: handlerFuncInfo{ @@ -53,7 +53,7 @@ func (s *Server) BindMiddlewareDefault(handlers ...HandlerFunc) { s.setHandler(ctx, setHandlerInput{ Prefix: "", Pattern: defaultMiddlewarePattern, - HandlerItem: &handlerItem{ + HandlerItem: &HandlerItem{ Type: HandlerTypeMiddleware, Name: gdebug.FuncPath(handler), Info: handlerFuncInfo{ diff --git a/net/ghttp/ghttp_server_router_serve.go b/net/ghttp/ghttp_server_router_serve.go index 8f5f5788e1e..0a2b214f132 100644 --- a/net/ghttp/ghttp_server_router_serve.go +++ b/net/ghttp/ghttp_server_router_serve.go @@ -56,8 +56,8 @@ func (s *Server) getHandlersWithCache(r *Request) (parsedItems []*handlerParsedI if xUrlPath := r.Header.Get(HeaderXUrlPath); xUrlPath != "" { path = xUrlPath } - var handlerKey = s.serveHandlerKey(method, path, host) - value, err := s.serveCache.GetOrSetFunc(ctx, handlerKey, func(ctx context.Context) (interface{}, error) { + var handlerCacheKey = s.serveHandlerKey(method, path, host) + value, err := s.serveCache.GetOrSetFunc(ctx, handlerCacheKey, func(ctx context.Context) (interface{}, error) { parsedItems, hasHook, hasServe = s.searchHandlers(method, path, host) if parsedItems != nil { return &handlerCacheItem{parsedItems, hasHook, hasServe}, nil @@ -152,7 +152,7 @@ func (s *Server) searchHandlers(method, path, domain string) (parsedItems []*han // As the tail of the list array has the most priority, it iterates the list array from its tail to head. for i := len(lists) - 1; i >= 0; i-- { for e := lists[i].Front(); e != nil; e = e.Next() { - item := e.Value.(*handlerItem) + item := e.Value.(*HandlerItem) // Filter repeated handler items, especially the middleware and hook handlers. // It is necessary, do not remove this checks logic unless you really know how it is necessary. if _, ok := repeatHandlerCheckMap[item.Id]; ok { @@ -212,7 +212,7 @@ func (s *Server) searchHandlers(method, path, domain string) (parsedItems []*han } } if parsedItemList.Len() > 0 { - index := 0 + var index = 0 parsedItems = make([]*handlerParsedItem, parsedItemList.Len()) for e := parsedItemList.Front(); e != nil; e = e.Next() { parsedItems[index] = e.Value.(*handlerParsedItem) @@ -223,7 +223,7 @@ func (s *Server) searchHandlers(method, path, domain string) (parsedItems []*han } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (item handlerItem) MarshalJSON() ([]byte, error) { +func (item HandlerItem) MarshalJSON() ([]byte, error) { switch item.Type { case HandlerTypeHook: return json.Marshal( diff --git a/net/ghttp/ghttp_server_service_handler.go b/net/ghttp/ghttp_server_service_handler.go index 35e15c9887f..25b4208f949 100644 --- a/net/ghttp/ghttp_server_service_handler.go +++ b/net/ghttp/ghttp_server_service_handler.go @@ -53,7 +53,7 @@ func (s *Server) doBindHandler(ctx context.Context, in doBindHandlerInput) { s.setHandler(ctx, setHandlerInput{ Prefix: in.Prefix, Pattern: in.Pattern, - HandlerItem: &handlerItem{ + HandlerItem: &HandlerItem{ Type: HandlerTypeHandler, Info: in.FuncInfo, Middleware: in.Middleware, @@ -63,7 +63,7 @@ func (s *Server) doBindHandler(ctx context.Context, in doBindHandlerInput) { } // bindHandlerByMap registers handlers to server using map. -func (s *Server) bindHandlerByMap(ctx context.Context, prefix string, m map[string]*handlerItem) { +func (s *Server) bindHandlerByMap(ctx context.Context, prefix string, m map[string]*HandlerItem) { for pattern, handler := range m { s.setHandler(ctx, setHandlerInput{ Prefix: prefix, diff --git a/net/ghttp/ghttp_server_service_object.go b/net/ghttp/ghttp_server_service_object.go index 9af28b97e87..8842841ab46 100644 --- a/net/ghttp/ghttp_server_service_object.go +++ b/net/ghttp/ghttp_server_service_object.go @@ -92,7 +92,7 @@ func (s *Server) doBindObject(ctx context.Context, in doBindObjectInput) { in.Pattern = s.serveHandlerKey("", path, domain) } var ( - handlerMap = make(map[string]*handlerItem) + handlerMap = make(map[string]*HandlerItem) reflectValue = reflect.ValueOf(in.Object) reflectType = reflectValue.Type() initFunc func(*Request) @@ -135,7 +135,7 @@ func (s *Server) doBindObject(ctx context.Context, in doBindObjectInput) { } key := s.mergeBuildInNameToPattern(in.Pattern, structName, methodName, true) - handlerMap[key] = &handlerItem{ + handlerMap[key] = &HandlerItem{ Name: fmt.Sprintf(`%s.%s.%s`, pkgPath, objName, methodName), Type: HandlerTypeObject, Info: funcInfo, @@ -162,7 +162,7 @@ func (s *Server) doBindObject(ctx context.Context, in doBindObjectInput) { if len(k) == 0 || k[0] == '@' { k = "/" + k } - handlerMap[k] = &handlerItem{ + handlerMap[k] = &HandlerItem{ Name: fmt.Sprintf(`%s.%s.%s`, pkgPath, objName, methodName), Type: HandlerTypeObject, Info: funcInfo, @@ -187,7 +187,7 @@ type doBindObjectMethodInput struct { func (s *Server) doBindObjectMethod(ctx context.Context, in doBindObjectMethodInput) { var ( - handlerMap = make(map[string]*handlerItem) + handlerMap = make(map[string]*HandlerItem) reflectValue = reflect.ValueOf(in.Object) reflectType = reflectValue.Type() initFunc func(*Request) @@ -231,7 +231,7 @@ func (s *Server) doBindObjectMethod(ctx context.Context, in doBindObjectMethodIn } key := s.mergeBuildInNameToPattern(in.Pattern, structName, methodName, false) - handlerMap[key] = &handlerItem{ + handlerMap[key] = &HandlerItem{ Name: fmt.Sprintf(`%s.%s.%s`, pkgPath, objName, methodName), Type: HandlerTypeObject, Info: funcInfo, @@ -246,7 +246,7 @@ func (s *Server) doBindObjectMethod(ctx context.Context, in doBindObjectMethodIn func (s *Server) doBindObjectRest(ctx context.Context, in doBindObjectInput) { var ( - handlerMap = make(map[string]*handlerItem) + handlerMap = make(map[string]*HandlerItem) reflectValue = reflect.ValueOf(in.Object) reflectType = reflectValue.Type() initFunc func(*Request) @@ -290,7 +290,7 @@ func (s *Server) doBindObjectRest(ctx context.Context, in doBindObjectInput) { } key := s.mergeBuildInNameToPattern(methodName+":"+in.Pattern, structName, methodName, false) - handlerMap[key] = &handlerItem{ + handlerMap[key] = &HandlerItem{ Name: fmt.Sprintf(`%s.%s.%s`, pkgPath, objName, methodName), Type: HandlerTypeObject, Info: funcInfo, From 559c1d02b90fe05ac204b9009c054679060f9717 Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 30 Apr 2022 15:53:56 +0800 Subject: [PATCH 14/70] add WhereBuilder feature for package gdb --- database/gdb/gdb_func.go | 2 +- database/gdb/gdb_model.go | 95 +++++------ database/gdb/gdb_model_builder.go | 143 ++++++++++++++++ database/gdb/gdb_model_builder_where.go | 159 ++++++++++++++++++ .../gdb/gdb_model_builder_where_prefix.go | 99 +++++++++++ database/gdb/gdb_model_builder_whereor.go | 118 +++++++++++++ .../gdb/gdb_model_builder_whereor_prefix.go | 91 ++++++++++ database/gdb/gdb_model_select.go | 115 ++----------- database/gdb/gdb_model_where.go | 108 +++--------- database/gdb/gdb_model_where_prefix.go | 50 ++---- database/gdb/gdb_model_whereor.go | 69 ++------ database/gdb/gdb_model_whereor_prefix.go | 48 ++---- 12 files changed, 731 insertions(+), 366 deletions(-) create mode 100644 database/gdb/gdb_model_builder.go create mode 100644 database/gdb/gdb_model_builder_where.go create mode 100644 database/gdb/gdb_model_builder_where_prefix.go create mode 100644 database/gdb/gdb_model_builder_whereor.go create mode 100644 database/gdb/gdb_model_builder_whereor_prefix.go diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index a687c4dbbd9..4682f7dabe8 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -332,7 +332,7 @@ func formatSql(sql string, args []interface{}) (newSql string, newArgs []interfa } type formatWhereHolderInput struct { - ModelWhereHolder + WhereHolder OmitNil bool OmitEmpty bool Schema string diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 6d72f9b21a4..4769aaa4d38 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -17,39 +17,39 @@ import ( // Model is core struct implementing the DAO for ORM. type Model struct { - db DB // Underlying DB interface. - tx *TX // Underlying TX interface. - rawSql string // rawSql is the raw SQL string which marks a raw SQL based Model not a table based Model. - schema string // Custom database schema. - linkType int // Mark for operation on master or slave. - tablesInit string // Table names when model initialization. - tables string // Operation table names, which can be more than one table names and aliases, like: "user", "user u", "user u, user_detail ud". - fields string // Operation fields, multiple fields joined using char ','. - fieldsEx string // Excluded operation fields, multiple fields joined using char ','. - withArray []interface{} // Arguments for With feature. - withAll bool // Enable model association operations on all objects that have "with" tag in the struct. - extraArgs []interface{} // Extra custom arguments for sql, which are prepended to the arguments before sql committed to underlying driver. - whereHolder []ModelWhereHolder // Condition strings for where operation. - groupBy string // Used for "group by" statement. - orderBy string // Used for "order by" statement. - having []interface{} // Used for "having..." statement. - start int // Used for "select ... start, limit ..." statement. - limit int // Used for "select ... start, limit ..." statement. - option int // Option for extra operation features. - offset int // Offset statement for some databases grammar. - data interface{} // Data for operation, which can be type of map/[]map/struct/*struct/string, etc. - batch int // Batch number for batch Insert/Replace/Save operations. - filter bool // Filter data and where key-value pairs according to the fields of the table. - distinct string // Force the query to only return distinct results. - lockInfo string // Lock for update or in shared lock. - cacheEnabled bool // Enable sql result cache feature, which is mainly for indicating cache duration(especially 0) usage. - cacheOption CacheOption // Cache option for query statement. - hookHandler HookHandler // Hook functions for model hook feature. - shardingHandler ShardingHandler // Custom sharding handler for sharding feature. - unscoped bool // Disables soft deleting features when select/delete operations. - safe bool // If true, it clones and returns a new model object whenever operation done; or else it changes the attribute of current model. - onDuplicate interface{} // onDuplicate is used for ON "DUPLICATE KEY UPDATE" statement. - onDuplicateEx interface{} // onDuplicateEx is used for excluding some columns ON "DUPLICATE KEY UPDATE" statement. + db DB // Underlying DB interface. + tx *TX // Underlying TX interface. + rawSql string // rawSql is the raw SQL string which marks a raw SQL based Model not a table based Model. + schema string // Custom database schema. + linkType int // Mark for operation on master or slave. + tablesInit string // Table names when model initialization. + tables string // Operation table names, which can be more than one table names and aliases, like: "user", "user u", "user u, user_detail ud". + fields string // Operation fields, multiple fields joined using char ','. + fieldsEx string // Excluded operation fields, multiple fields joined using char ','. + withArray []interface{} // Arguments for With feature. + withAll bool // Enable model association operations on all objects that have "with" tag in the struct. + extraArgs []interface{} // Extra custom arguments for sql, which are prepended to the arguments before sql committed to underlying driver. + whereBuilder *WhereBuilder // Condition builder for where operation. + groupBy string // Used for "group by" statement. + orderBy string // Used for "order by" statement. + having []interface{} // Used for "having..." statement. + start int // Used for "select ... start, limit ..." statement. + limit int // Used for "select ... start, limit ..." statement. + option int // Option for extra operation features. + offset int // Offset statement for some databases grammar. + data interface{} // Data for operation, which can be type of map/[]map/struct/*struct/string, etc. + batch int // Batch number for batch Insert/Replace/Save operations. + filter bool // Filter data and where key-value pairs according to the fields of the table. + distinct string // Force the query to only return distinct results. + lockInfo string // Lock for update or in shared lock. + cacheEnabled bool // Enable sql result cache feature, which is mainly for indicating cache duration(especially 0) usage. + cacheOption CacheOption // Cache option for query statement. + hookHandler HookHandler // Hook functions for model hook feature. + shardingHandler ShardingHandler // Custom sharding handler for sharding feature. + unscoped bool // Disables soft deleting features when select/delete operations. + safe bool // If true, it clones and returns a new model object whenever operation done; or else it changes the attribute of current model. + onDuplicate interface{} // onDuplicate is used for ON "DUPLICATE KEY UPDATE" statement. + onDuplicateEx interface{} // onDuplicateEx is used for excluding some columns ON "DUPLICATE KEY UPDATE" statement. } // ModelHandler is a function that handles given Model and returns a new Model that is custom modified. @@ -59,15 +59,6 @@ type ModelHandler func(m *Model) *Model // It returns true if it wants to continue chunking, or else it returns false to stop chunking. type ChunkHandler func(result Result, err error) bool -// ModelWhereHolder is the holder for where condition preparing. -type ModelWhereHolder struct { - Type string // Type of this holder. - Operator int // Operator for this holder. - Where interface{} // Where parameter, which can commonly be type of string/map/struct. - Args []interface{} // Arguments for where parameter. - Prefix string // Field prefix, eg: "user.", "order.". -} - const ( linkTypeMaster = 1 linkTypeSlave = 2 @@ -102,16 +93,16 @@ func (c *Core) Model(tableNameQueryOrStruct ...interface{}) *Model { if len(tableNameQueryOrStruct) > 1 { conditionStr := gconv.String(tableNameQueryOrStruct[0]) if gstr.Contains(conditionStr, "?") { - whereHolder := ModelWhereHolder{ + whereHolder := WhereHolder{ Where: conditionStr, Args: tableNameQueryOrStruct[1:], } tableStr, extraArgs = formatWhereHolder(ctx, c.db, formatWhereHolderInput{ - ModelWhereHolder: whereHolder, - OmitNil: false, - OmitEmpty: false, - Schema: "", - Table: "", + WhereHolder: whereHolder, + OmitNil: false, + OmitEmpty: false, + Schema: "", + Table: "", }) } } @@ -144,6 +135,7 @@ func (c *Core) Model(tableNameQueryOrStruct ...interface{}) *Model { filter: true, extraArgs: extraArgs, } + m.whereBuilder = m.Builder() if defaultModelSafe { m.safe = true } @@ -269,15 +261,14 @@ func (m *Model) Clone() *Model { } // Basic attributes copy. *newModel = *m + // WhereBuilder copy, note the attribute pointer. + newModel.whereBuilder = m.whereBuilder.Clone() + newModel.whereBuilder.model = newModel // Shallow copy slice attributes. if n := len(m.extraArgs); n > 0 { newModel.extraArgs = make([]interface{}, n) copy(newModel.extraArgs, m.extraArgs) } - if n := len(m.whereHolder); n > 0 { - newModel.whereHolder = make([]ModelWhereHolder, n) - copy(newModel.whereHolder, m.whereHolder) - } if n := len(m.withArray); n > 0 { newModel.withArray = make([]interface{}, n) copy(newModel.withArray, m.withArray) diff --git a/database/gdb/gdb_model_builder.go b/database/gdb/gdb_model_builder.go new file mode 100644 index 00000000000..0a1ccd6ffa4 --- /dev/null +++ b/database/gdb/gdb_model_builder.go @@ -0,0 +1,143 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package gdb + +import ( + "fmt" + + "github.com/gogf/gf/v2/text/gstr" +) + +type WhereBuilder struct { + model *Model // Bound to parent model. + whereHolder []WhereHolder // Condition strings for where operation. +} + +// WhereHolder is the holder for where condition preparing. +type WhereHolder struct { + Type string // Type of this holder. + Operator int // Operator for this holder. + Where interface{} // Where parameter, which can commonly be type of string/map/struct. + Args []interface{} // Arguments for where parameter. + Prefix string // Field prefix, eg: "user.", "order.". +} + +func (m *Model) Builder() *WhereBuilder { + b := &WhereBuilder{ + model: m, + whereHolder: make([]WhereHolder, 0), + } + return b +} + +// getBuilder creates and returns a cloned WhereBuilder of current WhereBuilder if `safe` is true, +// or else it returns the current WhereBuilder. +func (b *WhereBuilder) getBuilder() *WhereBuilder { + if !b.model.safe { + return b + } else { + return b.Clone() + } +} + +func (b *WhereBuilder) Clone() *WhereBuilder { + newBuilder := b.model.Builder() + newBuilder.whereHolder = make([]WhereHolder, len(b.whereHolder)) + copy(newBuilder.whereHolder, b.whereHolder) + return newBuilder +} + +func (b *WhereBuilder) Build() (conditionWhere string, conditionArgs []interface{}) { + var ( + ctx = b.model.GetCtx() + autoPrefix = b.model.getAutoPrefix() + tableForMappingAndFiltering = b.model.tables + ) + if len(b.whereHolder) > 0 { + for _, holder := range b.whereHolder { + if holder.Prefix == "" { + holder.Prefix = autoPrefix + } + switch holder.Operator { + case whereHolderOperatorWhere: + if conditionWhere == "" { + newWhere, newArgs := formatWhereHolder(ctx, b.model.db, formatWhereHolderInput{ + WhereHolder: holder, + OmitNil: b.model.option&optionOmitNilWhere > 0, + OmitEmpty: b.model.option&optionOmitEmptyWhere > 0, + Schema: b.model.schema, + Table: tableForMappingAndFiltering, + }) + if len(newWhere) > 0 { + conditionWhere = newWhere + conditionArgs = newArgs + } + continue + } + fallthrough + + case whereHolderOperatorAnd: + newWhere, newArgs := formatWhereHolder(ctx, b.model.db, formatWhereHolderInput{ + WhereHolder: holder, + OmitNil: b.model.option&optionOmitNilWhere > 0, + OmitEmpty: b.model.option&optionOmitEmptyWhere > 0, + Schema: b.model.schema, + Table: tableForMappingAndFiltering, + }) + if len(newWhere) > 0 { + if len(conditionWhere) == 0 { + conditionWhere = newWhere + } else if conditionWhere[0] == '(' { + conditionWhere = fmt.Sprintf(`%s AND (%s)`, conditionWhere, newWhere) + } else { + conditionWhere = fmt.Sprintf(`(%s) AND (%s)`, conditionWhere, newWhere) + } + conditionArgs = append(conditionArgs, newArgs...) + } + + case whereHolderOperatorOr: + newWhere, newArgs := formatWhereHolder(ctx, b.model.db, formatWhereHolderInput{ + WhereHolder: holder, + OmitNil: b.model.option&optionOmitNilWhere > 0, + OmitEmpty: b.model.option&optionOmitEmptyWhere > 0, + Schema: b.model.schema, + Table: tableForMappingAndFiltering, + }) + if len(newWhere) > 0 { + if len(conditionWhere) == 0 { + conditionWhere = newWhere + } else if conditionWhere[0] == '(' { + conditionWhere = fmt.Sprintf(`%s OR (%s)`, conditionWhere, newWhere) + } else { + conditionWhere = fmt.Sprintf(`(%s) OR (%s)`, conditionWhere, newWhere) + } + conditionArgs = append(conditionArgs, newArgs...) + } + } + } + } + // Soft deletion. + softDeletingCondition := b.model.getConditionForSoftDeleting() + if b.model.rawSql != "" && conditionWhere != "" { + if gstr.ContainsI(b.model.rawSql, " WHERE ") { + conditionWhere = " AND " + conditionWhere + } else { + conditionWhere = " WHERE " + conditionWhere + } + } else if !b.model.unscoped && softDeletingCondition != "" { + if conditionWhere == "" { + conditionWhere = fmt.Sprintf(` WHERE %s`, softDeletingCondition) + } else { + conditionWhere = fmt.Sprintf(` WHERE (%s) AND %s`, conditionWhere, softDeletingCondition) + } + } else { + if conditionWhere != "" { + conditionWhere = " WHERE " + conditionWhere + } + } + return +} diff --git a/database/gdb/gdb_model_builder_where.go b/database/gdb/gdb_model_builder_where.go new file mode 100644 index 00000000000..5803f8d8297 --- /dev/null +++ b/database/gdb/gdb_model_builder_where.go @@ -0,0 +1,159 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package gdb + +import ( + "fmt" + + "github.com/gogf/gf/v2/text/gstr" +) + +// doWhereType sets the condition statement for the model. The parameter `where` can be type of +// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, +// multiple conditions will be joined into where statement using "AND". +func (b *WhereBuilder) doWhereType(t string, where interface{}, args ...interface{}) *WhereBuilder { + builder := b.getBuilder() + if builder.whereHolder == nil { + builder.whereHolder = make([]WhereHolder, 0) + } + if t == "" { + if len(args) == 0 { + t = whereHolderTypeNoArgs + } else { + t = whereHolderTypeDefault + } + } + builder.whereHolder = append(builder.whereHolder, WhereHolder{ + Type: t, + Operator: whereHolderOperatorWhere, + Where: where, + Args: args, + }) + return builder +} + +// doWherefType builds condition string using fmt.Sprintf and arguments. +// Note that if the number of `args` is more than the placeholder in `format`, +// the extra `args` will be used as the where condition arguments of the Model. +func (b *WhereBuilder) doWherefType(t string, format string, args ...interface{}) *WhereBuilder { + var ( + placeHolderCount = gstr.Count(format, "?") + conditionStr = fmt.Sprintf(format, args[:len(args)-placeHolderCount]...) + ) + return b.doWhereType(t, conditionStr, args[len(args)-placeHolderCount:]...) +} + +// Where sets the condition statement for the builder. The parameter `where` can be type of +// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, +// multiple conditions will be joined into where statement using "AND". +// Eg: +// Where("uid=10000") +// Where("uid", 10000) +// Where("money>? AND name like ?", 99999, "vip_%") +// Where("uid", 1).Where("name", "john") +// Where("status IN (?)", g.Slice{1,2,3}) +// Where("age IN(?,?)", 18, 50) +// Where(User{ Id : 1, UserName : "john"}). +func (b *WhereBuilder) Where(where interface{}, args ...interface{}) *WhereBuilder { + return b.doWhereType(``, where, args...) +} + +// Wheref builds condition string using fmt.Sprintf and arguments. +// Note that if the number of `args` is more than the placeholder in `format`, +// the extra `args` will be used as the where condition arguments of the Model. +// Eg: +// Wheref(`amount WHERE `amount`<100 and status='paid' +// Wheref(`amount<%d and status=%s`, 100, "paid") => WHERE `amount`<100 and status='paid' +func (b *WhereBuilder) Wheref(format string, args ...interface{}) *WhereBuilder { + return b.doWherefType(``, format, args...) +} + +// WherePri does the same logic as Model.Where except that if the parameter `where` +// is a single condition like int/string/float/slice, it treats the condition as the primary +// key value. That is, if primary key is "id" and given `where` parameter as "123", the +// WherePri function treats the condition as "id=123", but Model.Where treats the condition +// as string "123". +func (b *WhereBuilder) WherePri(where interface{}, args ...interface{}) *WhereBuilder { + if len(args) > 0 { + return b.Where(where, args...) + } + newWhere := GetPrimaryKeyCondition(b.model.getPrimaryKey(), where) + return b.Where(newWhere[0], newWhere[1:]...) +} + +// WhereLT builds `column < value` statement. +func (b *WhereBuilder) WhereLT(column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s < ?`, b.model.QuoteWord(column), value) +} + +// WhereLTE builds `column <= value` statement. +func (b *WhereBuilder) WhereLTE(column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s <= ?`, b.model.QuoteWord(column), value) +} + +// WhereGT builds `column > value` statement. +func (b *WhereBuilder) WhereGT(column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s > ?`, b.model.QuoteWord(column), value) +} + +// WhereGTE builds `column >= value` statement. +func (b *WhereBuilder) WhereGTE(column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s >= ?`, b.model.QuoteWord(column), value) +} + +// WhereBetween builds `column BETWEEN min AND max` statement. +func (b *WhereBuilder) WhereBetween(column string, min, max interface{}) *WhereBuilder { + return b.Wheref(`%s BETWEEN ? AND ?`, b.model.QuoteWord(column), min, max) +} + +// WhereLike builds `column LIKE like` statement. +func (b *WhereBuilder) WhereLike(column string, like string) *WhereBuilder { + return b.Wheref(`%s LIKE ?`, b.model.QuoteWord(column), like) +} + +// WhereIn builds `column IN (in)` statement. +func (b *WhereBuilder) WhereIn(column string, in interface{}) *WhereBuilder { + return b.doWherefType(whereHolderTypeIn, `%s IN (?)`, b.model.QuoteWord(column), in) +} + +// WhereNull builds `columns[0] IS NULL AND columns[1] IS NULL ...` statement. +func (b *WhereBuilder) WhereNull(columns ...string) *WhereBuilder { + builder := b + for _, column := range columns { + builder = builder.Wheref(`%s IS NULL`, b.model.QuoteWord(column)) + } + return builder +} + +// WhereNotBetween builds `column NOT BETWEEN min AND max` statement. +func (b *WhereBuilder) WhereNotBetween(column string, min, max interface{}) *WhereBuilder { + return b.Wheref(`%s NOT BETWEEN ? AND ?`, b.model.QuoteWord(column), min, max) +} + +// WhereNotLike builds `column NOT LIKE like` statement. +func (b *WhereBuilder) WhereNotLike(column string, like interface{}) *WhereBuilder { + return b.Wheref(`%s NOT LIKE ?`, b.model.QuoteWord(column), like) +} + +// WhereNot builds `column != value` statement. +func (b *WhereBuilder) WhereNot(column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s != ?`, b.model.QuoteWord(column), value) +} + +// WhereNotIn builds `column NOT IN (in)` statement. +func (b *WhereBuilder) WhereNotIn(column string, in interface{}) *WhereBuilder { + return b.doWherefType(whereHolderTypeIn, `%s NOT IN (?)`, b.model.QuoteWord(column), in) +} + +// WhereNotNull builds `columns[0] IS NOT NULL AND columns[1] IS NOT NULL ...` statement. +func (b *WhereBuilder) WhereNotNull(columns ...string) *WhereBuilder { + builder := b + for _, column := range columns { + builder = builder.Wheref(`%s IS NOT NULL`, b.model.QuoteWord(column)) + } + return builder +} diff --git a/database/gdb/gdb_model_builder_where_prefix.go b/database/gdb/gdb_model_builder_where_prefix.go new file mode 100644 index 00000000000..7cc189901b1 --- /dev/null +++ b/database/gdb/gdb_model_builder_where_prefix.go @@ -0,0 +1,99 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package gdb + +// WherePrefix performs as Where, but it adds prefix to each field in where statement. +// Eg: +// WherePrefix("order", "status", "paid") => WHERE `order`.`status`='paid' +// WherePrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE `order`.`status`='paid' AND `order`.`channel`='bank' +func (b *WhereBuilder) WherePrefix(prefix string, where interface{}, args ...interface{}) *WhereBuilder { + builder := b.getBuilder() + if builder.whereHolder == nil { + builder.whereHolder = make([]WhereHolder, 0) + } + builder.whereHolder = append(builder.whereHolder, WhereHolder{ + Type: whereHolderTypeDefault, + Operator: whereHolderOperatorWhere, + Where: where, + Args: args, + Prefix: prefix, + }) + return builder +} + +// WherePrefixLT builds `prefix.column < value` statement. +func (b *WhereBuilder) WherePrefixLT(prefix string, column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s.%s < ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WherePrefixLTE builds `prefix.column <= value` statement. +func (b *WhereBuilder) WherePrefixLTE(prefix string, column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s.%s <= ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WherePrefixGT builds `prefix.column > value` statement. +func (b *WhereBuilder) WherePrefixGT(prefix string, column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s.%s > ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WherePrefixGTE builds `prefix.column >= value` statement. +func (b *WhereBuilder) WherePrefixGTE(prefix string, column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s.%s >= ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WherePrefixBetween builds `prefix.column BETWEEN min AND max` statement. +func (b *WhereBuilder) WherePrefixBetween(prefix string, column string, min, max interface{}) *WhereBuilder { + return b.Wheref(`%s.%s BETWEEN ? AND ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), min, max) +} + +// WherePrefixLike builds `prefix.column LIKE like` statement. +func (b *WhereBuilder) WherePrefixLike(prefix string, column string, like interface{}) *WhereBuilder { + return b.Wheref(`%s.%s LIKE ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), like) +} + +// WherePrefixIn builds `prefix.column IN (in)` statement. +func (b *WhereBuilder) WherePrefixIn(prefix string, column string, in interface{}) *WhereBuilder { + return b.doWherefType(whereHolderTypeIn, `%s.%s IN (?)`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), in) +} + +// WherePrefixNull builds `prefix.columns[0] IS NULL AND prefix.columns[1] IS NULL ...` statement. +func (b *WhereBuilder) WherePrefixNull(prefix string, columns ...string) *WhereBuilder { + builder := b + for _, column := range columns { + builder = builder.Wheref(`%s.%s IS NULL`, b.model.QuoteWord(prefix), b.model.QuoteWord(column)) + } + return builder +} + +// WherePrefixNotBetween builds `prefix.column NOT BETWEEN min AND max` statement. +func (b *WhereBuilder) WherePrefixNotBetween(prefix string, column string, min, max interface{}) *WhereBuilder { + return b.Wheref(`%s.%s NOT BETWEEN ? AND ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), min, max) +} + +// WherePrefixNotLike builds `prefix.column NOT LIKE like` statement. +func (b *WhereBuilder) WherePrefixNotLike(prefix string, column string, like interface{}) *WhereBuilder { + return b.Wheref(`%s.%s NOT LIKE ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), like) +} + +// WherePrefixNot builds `prefix.column != value` statement. +func (b *WhereBuilder) WherePrefixNot(prefix string, column string, value interface{}) *WhereBuilder { + return b.Wheref(`%s.%s != ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WherePrefixNotIn builds `prefix.column NOT IN (in)` statement. +func (b *WhereBuilder) WherePrefixNotIn(prefix string, column string, in interface{}) *WhereBuilder { + return b.doWherefType(whereHolderTypeIn, `%s.%s NOT IN (?)`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), in) +} + +// WherePrefixNotNull builds `prefix.columns[0] IS NOT NULL AND prefix.columns[1] IS NOT NULL ...` statement. +func (b *WhereBuilder) WherePrefixNotNull(prefix string, columns ...string) *WhereBuilder { + builder := b + for _, column := range columns { + builder = builder.Wheref(`%s.%s IS NOT NULL`, b.model.QuoteWord(prefix), b.model.QuoteWord(column)) + } + return builder +} diff --git a/database/gdb/gdb_model_builder_whereor.go b/database/gdb/gdb_model_builder_whereor.go new file mode 100644 index 00000000000..993c4def37f --- /dev/null +++ b/database/gdb/gdb_model_builder_whereor.go @@ -0,0 +1,118 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package gdb + +import ( + "fmt" + + "github.com/gogf/gf/v2/text/gstr" +) + +// WhereOr adds "OR" condition to the where statement. +func (b *WhereBuilder) doWhereOrType(t string, where interface{}, args ...interface{}) *WhereBuilder { + builder := b.getBuilder() + if builder.whereHolder == nil { + builder.whereHolder = make([]WhereHolder, 0) + } + builder.whereHolder = append(builder.whereHolder, WhereHolder{ + Type: t, + Operator: whereHolderOperatorOr, + Where: where, + Args: args, + }) + return builder +} + +// WhereOrf builds `OR` condition string using fmt.Sprintf and arguments. +func (b *WhereBuilder) doWhereOrfType(t string, format string, args ...interface{}) *WhereBuilder { + var ( + placeHolderCount = gstr.Count(format, "?") + conditionStr = fmt.Sprintf(format, args[:len(args)-placeHolderCount]...) + ) + return b.doWhereOrType(t, conditionStr, args[len(args)-placeHolderCount:]...) +} + +// WhereOr adds "OR" condition to the where statement. +func (b *WhereBuilder) WhereOr(where interface{}, args ...interface{}) *WhereBuilder { + return b.doWhereOrType(``, where, args...) +} + +// WhereOrf builds `OR` condition string using fmt.Sprintf and arguments. +// Eg: +// WhereOrf(`amount WHERE xxx OR `amount`<100 and status='paid' +// WhereOrf(`amount<%d and status=%s`, 100, "paid") => WHERE xxx OR `amount`<100 and status='paid' +func (b *WhereBuilder) WhereOrf(format string, args ...interface{}) *WhereBuilder { + return b.doWhereOrfType(``, format, args...) +} + +// WhereOrLT builds `column < value` statement in `OR` conditions.. +func (b *WhereBuilder) WhereOrLT(column string, value interface{}) *WhereBuilder { + return b.WhereOrf(`%s < ?`, column, value) +} + +// WhereOrLTE builds `column <= value` statement in `OR` conditions.. +func (b *WhereBuilder) WhereOrLTE(column string, value interface{}) *WhereBuilder { + return b.WhereOrf(`%s <= ?`, column, value) +} + +// WhereOrGT builds `column > value` statement in `OR` conditions.. +func (b *WhereBuilder) WhereOrGT(column string, value interface{}) *WhereBuilder { + return b.WhereOrf(`%s > ?`, column, value) +} + +// WhereOrGTE builds `column >= value` statement in `OR` conditions.. +func (b *WhereBuilder) WhereOrGTE(column string, value interface{}) *WhereBuilder { + return b.WhereOrf(`%s >= ?`, column, value) +} + +// WhereOrBetween builds `column BETWEEN min AND max` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrBetween(column string, min, max interface{}) *WhereBuilder { + return b.WhereOrf(`%s BETWEEN ? AND ?`, b.model.QuoteWord(column), min, max) +} + +// WhereOrLike builds `column LIKE like` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrLike(column string, like interface{}) *WhereBuilder { + return b.WhereOrf(`%s LIKE ?`, b.model.QuoteWord(column), like) +} + +// WhereOrIn builds `column IN (in)` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrIn(column string, in interface{}) *WhereBuilder { + return b.doWhereOrfType(whereHolderTypeIn, `%s IN (?)`, b.model.QuoteWord(column), in) +} + +// WhereOrNull builds `columns[0] IS NULL OR columns[1] IS NULL ...` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrNull(columns ...string) *WhereBuilder { + var builder *WhereBuilder + for _, column := range columns { + builder = b.WhereOrf(`%s IS NULL`, b.model.QuoteWord(column)) + } + return builder +} + +// WhereOrNotBetween builds `column NOT BETWEEN min AND max` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrNotBetween(column string, min, max interface{}) *WhereBuilder { + return b.WhereOrf(`%s NOT BETWEEN ? AND ?`, b.model.QuoteWord(column), min, max) +} + +// WhereOrNotLike builds `column NOT LIKE like` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrNotLike(column string, like interface{}) *WhereBuilder { + return b.WhereOrf(`%s NOT LIKE ?`, b.model.QuoteWord(column), like) +} + +// WhereOrNotIn builds `column NOT IN (in)` statement. +func (b *WhereBuilder) WhereOrNotIn(column string, in interface{}) *WhereBuilder { + return b.doWhereOrfType(whereHolderTypeIn, `%s NOT IN (?)`, b.model.QuoteWord(column), in) +} + +// WhereOrNotNull builds `columns[0] IS NOT NULL OR columns[1] IS NOT NULL ...` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrNotNull(columns ...string) *WhereBuilder { + builder := b + for _, column := range columns { + builder = builder.WhereOrf(`%s IS NOT NULL`, b.model.QuoteWord(column)) + } + return builder +} diff --git a/database/gdb/gdb_model_builder_whereor_prefix.go b/database/gdb/gdb_model_builder_whereor_prefix.go new file mode 100644 index 00000000000..c720b7c3f1c --- /dev/null +++ b/database/gdb/gdb_model_builder_whereor_prefix.go @@ -0,0 +1,91 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package gdb + +// WhereOrPrefix performs as WhereOr, but it adds prefix to each field in where statement. +// Eg: +// WhereOrPrefix("order", "status", "paid") => WHERE xxx OR (`order`.`status`='paid') +// WhereOrPrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE xxx OR (`order`.`status`='paid' AND `order`.`channel`='bank') +func (b *WhereBuilder) WhereOrPrefix(prefix string, where interface{}, args ...interface{}) *WhereBuilder { + builder := b.getBuilder() + builder.whereHolder = append(builder.whereHolder, WhereHolder{ + Type: whereHolderTypeDefault, + Operator: whereHolderOperatorOr, + Where: where, + Args: args, + Prefix: prefix, + }) + return builder +} + +// WhereOrPrefixLT builds `prefix.column < value` statement in `OR` conditions.. +func (b *WhereBuilder) WhereOrPrefixLT(prefix string, column string, value interface{}) *WhereBuilder { + return b.WhereOrf(`%s.%s < ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WhereOrPrefixLTE builds `prefix.column <= value` statement in `OR` conditions.. +func (b *WhereBuilder) WhereOrPrefixLTE(prefix string, column string, value interface{}) *WhereBuilder { + return b.WhereOrf(`%s.%s <= ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WhereOrPrefixGT builds `prefix.column > value` statement in `OR` conditions.. +func (b *WhereBuilder) WhereOrPrefixGT(prefix string, column string, value interface{}) *WhereBuilder { + return b.WhereOrf(`%s.%s > ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WhereOrPrefixGTE builds `prefix.column >= value` statement in `OR` conditions.. +func (b *WhereBuilder) WhereOrPrefixGTE(prefix string, column string, value interface{}) *WhereBuilder { + return b.WhereOrf(`%s.%s >= ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) +} + +// WhereOrPrefixBetween builds `prefix.column BETWEEN min AND max` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrPrefixBetween(prefix string, column string, min, max interface{}) *WhereBuilder { + return b.WhereOrf(`%s.%s BETWEEN ? AND ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), min, max) +} + +// WhereOrPrefixLike builds `prefix.column LIKE like` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrPrefixLike(prefix string, column string, like interface{}) *WhereBuilder { + return b.WhereOrf(`%s.%s LIKE ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), like) +} + +// WhereOrPrefixIn builds `prefix.column IN (in)` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrPrefixIn(prefix string, column string, in interface{}) *WhereBuilder { + return b.doWhereOrfType(whereHolderTypeIn, `%s.%s IN (?)`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), in) +} + +// WhereOrPrefixNull builds `prefix.columns[0] IS NULL OR prefix.columns[1] IS NULL ...` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrPrefixNull(prefix string, columns ...string) *WhereBuilder { + builder := b + for _, column := range columns { + builder = builder.WhereOrf(`%s.%s IS NULL`, b.model.QuoteWord(prefix), b.model.QuoteWord(column)) + } + return builder +} + +// WhereOrPrefixNotBetween builds `prefix.column NOT BETWEEN min AND max` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrPrefixNotBetween(prefix string, column string, min, max interface{}) *WhereBuilder { + return b.WhereOrf(`%s.%s NOT BETWEEN ? AND ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), min, max) +} + +// WhereOrPrefixNotLike builds `prefix.column NOT LIKE like` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrPrefixNotLike(prefix string, column string, like interface{}) *WhereBuilder { + return b.WhereOrf(`%s.%s NOT LIKE ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), like) +} + +// WhereOrPrefixNotIn builds `prefix.column NOT IN (in)` statement. +func (b *WhereBuilder) WhereOrPrefixNotIn(prefix string, column string, in interface{}) *WhereBuilder { + return b.doWhereOrfType(whereHolderTypeIn, `%s.%s NOT IN (?)`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), in) +} + +// WhereOrPrefixNotNull builds `prefix.columns[0] IS NOT NULL OR prefix.columns[1] IS NOT NULL ...` statement in `OR` conditions. +func (b *WhereBuilder) WhereOrPrefixNotNull(prefix string, columns ...string) *WhereBuilder { + builder := b + for _, column := range columns { + builder = builder.WhereOrf(`%s.%s IS NOT NULL`, b.model.QuoteWord(prefix), b.model.QuoteWord(column)) + } + return builder +} diff --git a/database/gdb/gdb_model_select.go b/database/gdb/gdb_model_select.go index 27b1ac185b7..b7f782f4ab1 100644 --- a/database/gdb/gdb_model_select.go +++ b/database/gdb/gdb_model_select.go @@ -594,122 +594,41 @@ func (m *Model) getFormattedSqlAndArgs(ctx context.Context, queryType int, limit } } -// formatCondition formats where arguments of the model and returns a new condition sql and its arguments. -// Note that this function does not change any attribute value of the `m`. -// -// The parameter `limit1` specifies whether limits querying only one record if m.limit is not set. -func (m *Model) formatCondition(ctx context.Context, limit1 bool, isCountStatement bool) (conditionWhere string, conditionExtra string, conditionArgs []interface{}) { +func (m *Model) getAutoPrefix() string { autoPrefix := "" if gstr.Contains(m.tables, " JOIN ") { autoPrefix = m.db.GetCore().QuoteWord( m.db.GetCore().guessPrimaryTableName(m.tablesInit), ) } - var ( - tableForMappingAndFiltering = m.tables - ) - if len(m.whereHolder) > 0 { - for _, holder := range m.whereHolder { - tableForMappingAndFiltering = m.tables - if holder.Prefix == "" { - holder.Prefix = autoPrefix - } - - switch holder.Operator { - case whereHolderOperatorWhere: - if conditionWhere == "" { - newWhere, newArgs := formatWhereHolder(ctx, m.db, formatWhereHolderInput{ - ModelWhereHolder: holder, - OmitNil: m.option&optionOmitNilWhere > 0, - OmitEmpty: m.option&optionOmitEmptyWhere > 0, - Schema: m.schema, - Table: tableForMappingAndFiltering, - }) - if len(newWhere) > 0 { - conditionWhere = newWhere - conditionArgs = newArgs - } - continue - } - fallthrough - - case whereHolderOperatorAnd: - newWhere, newArgs := formatWhereHolder(ctx, m.db, formatWhereHolderInput{ - ModelWhereHolder: holder, - OmitNil: m.option&optionOmitNilWhere > 0, - OmitEmpty: m.option&optionOmitEmptyWhere > 0, - Schema: m.schema, - Table: tableForMappingAndFiltering, - }) - if len(newWhere) > 0 { - if len(conditionWhere) == 0 { - conditionWhere = newWhere - } else if conditionWhere[0] == '(' { - conditionWhere = fmt.Sprintf(`%s AND (%s)`, conditionWhere, newWhere) - } else { - conditionWhere = fmt.Sprintf(`(%s) AND (%s)`, conditionWhere, newWhere) - } - conditionArgs = append(conditionArgs, newArgs...) - } - - case whereHolderOperatorOr: - newWhere, newArgs := formatWhereHolder(ctx, m.db, formatWhereHolderInput{ - ModelWhereHolder: holder, - OmitNil: m.option&optionOmitNilWhere > 0, - OmitEmpty: m.option&optionOmitEmptyWhere > 0, - Schema: m.schema, - Table: tableForMappingAndFiltering, - }) - if len(newWhere) > 0 { - if len(conditionWhere) == 0 { - conditionWhere = newWhere - } else if conditionWhere[0] == '(' { - conditionWhere = fmt.Sprintf(`%s OR (%s)`, conditionWhere, newWhere) - } else { - conditionWhere = fmt.Sprintf(`(%s) OR (%s)`, conditionWhere, newWhere) - } - conditionArgs = append(conditionArgs, newArgs...) - } - } - } - } - // Soft deletion. - softDeletingCondition := m.getConditionForSoftDeleting() - if m.rawSql != "" && conditionWhere != "" { - if gstr.ContainsI(m.rawSql, " WHERE ") { - conditionWhere = " AND " + conditionWhere - } else { - conditionWhere = " WHERE " + conditionWhere - } - } else if !m.unscoped && softDeletingCondition != "" { - if conditionWhere == "" { - conditionWhere = fmt.Sprintf(` WHERE %s`, softDeletingCondition) - } else { - conditionWhere = fmt.Sprintf(` WHERE (%s) AND %s`, conditionWhere, softDeletingCondition) - } - } else { - if conditionWhere != "" { - conditionWhere = " WHERE " + conditionWhere - } - } + return autoPrefix +} +// formatCondition formats where arguments of the model and returns a new condition sql and its arguments. +// Note that this function does not change any attribute value of the `m`. +// +// The parameter `limit1` specifies whether limits querying only one record if m.limit is not set. +func (m *Model) formatCondition(ctx context.Context, limit1 bool, isCountStatement bool) (conditionWhere string, conditionExtra string, conditionArgs []interface{}) { + var autoPrefix = m.getAutoPrefix() // GROUP BY. if m.groupBy != "" { conditionExtra += " GROUP BY " + m.groupBy } + // WHERE + conditionWhere, conditionArgs = m.whereBuilder.Build() // HAVING. if len(m.having) > 0 { - havingHolder := ModelWhereHolder{ + havingHolder := WhereHolder{ Where: m.having[0], Args: gconv.Interfaces(m.having[1]), Prefix: autoPrefix, } havingStr, havingArgs := formatWhereHolder(ctx, m.db, formatWhereHolderInput{ - ModelWhereHolder: havingHolder, - OmitNil: m.option&optionOmitNilWhere > 0, - OmitEmpty: m.option&optionOmitEmptyWhere > 0, - Schema: m.schema, - Table: m.tables, + WhereHolder: havingHolder, + OmitNil: m.option&optionOmitNilWhere > 0, + OmitEmpty: m.option&optionOmitEmptyWhere > 0, + Schema: m.schema, + Table: m.tables, }) if len(havingStr) > 0 { conditionExtra += " HAVING " + havingStr diff --git a/database/gdb/gdb_model_where.go b/database/gdb/gdb_model_where.go index 0b168eb642e..09566db91f9 100644 --- a/database/gdb/gdb_model_where.go +++ b/database/gdb/gdb_model_where.go @@ -2,158 +2,88 @@ // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. +// You can obtain one at https://githum.com/gogf/gf. package gdb -import ( - "fmt" - - "github.com/gogf/gf/v2/text/gstr" -) - -// doWhereType sets the condition statement for the model. The parameter `where` can be type of -// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, -// multiple conditions will be joined into where statement using "AND". -func (m *Model) doWhereType(t string, where interface{}, args ...interface{}) *Model { +func (m *Model) callWhereBuilder(builder *WhereBuilder) *Model { model := m.getModel() - if model.whereHolder == nil { - model.whereHolder = make([]ModelWhereHolder, 0) - } - if t == "" { - if len(args) == 0 { - t = whereHolderTypeNoArgs - } else { - t = whereHolderTypeDefault - } - } - model.whereHolder = append(model.whereHolder, ModelWhereHolder{ - Type: t, - Operator: whereHolderOperatorWhere, - Where: where, - Args: args, - }) + model.whereBuilder = builder return model } -// doWherefType builds condition string using fmt.Sprintf and arguments. -// Note that if the number of `args` is more than the placeholder in `format`, -// the extra `args` will be used as the where condition arguments of the Model. -func (m *Model) doWherefType(t string, format string, args ...interface{}) *Model { - var ( - placeHolderCount = gstr.Count(format, "?") - conditionStr = fmt.Sprintf(format, args[:len(args)-placeHolderCount]...) - ) - return m.doWhereType(t, conditionStr, args[len(args)-placeHolderCount:]...) -} - -// Where sets the condition statement for the model. The parameter `where` can be type of -// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, -// multiple conditions will be joined into where statement using "AND". -// Eg: -// Where("uid=10000") -// Where("uid", 10000) -// Where("money>? AND name like ?", 99999, "vip_%") -// Where("uid", 1).Where("name", "john") -// Where("status IN (?)", g.Slice{1,2,3}) -// Where("age IN(?,?)", 18, 50) -// Where(User{ Id : 1, UserName : "john"}). func (m *Model) Where(where interface{}, args ...interface{}) *Model { - return m.doWhereType(``, where, args...) + return m.callWhereBuilder(m.whereBuilder.Where(where, args...)) } -// Wheref builds condition string using fmt.Sprintf and arguments. -// Note that if the number of `args` is more than the placeholder in `format`, -// the extra `args` will be used as the where condition arguments of the Model. -// Eg: -// Wheref(`amount WHERE `amount`<100 and status='paid' -// Wheref(`amount<%d and status=%s`, 100, "paid") => WHERE `amount`<100 and status='paid' func (m *Model) Wheref(format string, args ...interface{}) *Model { - return m.doWherefType(``, format, args...) + return m.callWhereBuilder(m.whereBuilder.Wheref(format, args...)) } -// WherePri does the same logic as Model.Where except that if the parameter `where` -// is a single condition like int/string/float/slice, it treats the condition as the primary -// key value. That is, if primary key is "id" and given `where` parameter as "123", the -// WherePri function treats the condition as "id=123", but Model.Where treats the condition -// as string "123". func (m *Model) WherePri(where interface{}, args ...interface{}) *Model { - if len(args) > 0 { - return m.Where(where, args...) - } - newWhere := GetPrimaryKeyCondition(m.getPrimaryKey(), where) - return m.Where(newWhere[0], newWhere[1:]...) + return m.callWhereBuilder(m.whereBuilder.WherePri(where, args...)) } -// WhereLT builds `column < value` statement. func (m *Model) WhereLT(column string, value interface{}) *Model { - return m.Wheref(`%s < ?`, m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereLT(column, value)) } // WhereLTE builds `column <= value` statement. func (m *Model) WhereLTE(column string, value interface{}) *Model { - return m.Wheref(`%s <= ?`, m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereLTE(column, value)) } // WhereGT builds `column > value` statement. func (m *Model) WhereGT(column string, value interface{}) *Model { - return m.Wheref(`%s > ?`, m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereGT(column, value)) } // WhereGTE builds `column >= value` statement. func (m *Model) WhereGTE(column string, value interface{}) *Model { - return m.Wheref(`%s >= ?`, m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereGTE(column, value)) } // WhereBetween builds `column BETWEEN min AND max` statement. func (m *Model) WhereBetween(column string, min, max interface{}) *Model { - return m.Wheref(`%s BETWEEN ? AND ?`, m.QuoteWord(column), min, max) + return m.callWhereBuilder(m.whereBuilder.WhereBetween(column, min, max)) } // WhereLike builds `column LIKE like` statement. func (m *Model) WhereLike(column string, like string) *Model { - return m.Wheref(`%s LIKE ?`, m.QuoteWord(column), like) + return m.callWhereBuilder(m.whereBuilder.WhereLike(column, like)) } // WhereIn builds `column IN (in)` statement. func (m *Model) WhereIn(column string, in interface{}) *Model { - return m.doWherefType(whereHolderTypeIn, `%s IN (?)`, m.QuoteWord(column), in) + return m.callWhereBuilder(m.whereBuilder.WhereIn(column, in)) } // WhereNull builds `columns[0] IS NULL AND columns[1] IS NULL ...` statement. func (m *Model) WhereNull(columns ...string) *Model { - model := m - for _, column := range columns { - model = m.Wheref(`%s IS NULL`, m.QuoteWord(column)) - } - return model + return m.callWhereBuilder(m.whereBuilder.WhereNull(columns...)) } // WhereNotBetween builds `column NOT BETWEEN min AND max` statement. func (m *Model) WhereNotBetween(column string, min, max interface{}) *Model { - return m.Wheref(`%s NOT BETWEEN ? AND ?`, m.QuoteWord(column), min, max) + return m.callWhereBuilder(m.whereBuilder.WhereNotBetween(column, min, max)) } // WhereNotLike builds `column NOT LIKE like` statement. func (m *Model) WhereNotLike(column string, like interface{}) *Model { - return m.Wheref(`%s NOT LIKE ?`, m.QuoteWord(column), like) + return m.callWhereBuilder(m.whereBuilder.WhereNotLike(column, like)) } // WhereNot builds `column != value` statement. func (m *Model) WhereNot(column string, value interface{}) *Model { - return m.Wheref(`%s != ?`, m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereNot(column, value)) } // WhereNotIn builds `column NOT IN (in)` statement. func (m *Model) WhereNotIn(column string, in interface{}) *Model { - return m.doWherefType(whereHolderTypeIn, `%s NOT IN (?)`, m.QuoteWord(column), in) + return m.callWhereBuilder(m.whereBuilder.WhereNotIn(column, in)) } // WhereNotNull builds `columns[0] IS NOT NULL AND columns[1] IS NOT NULL ...` statement. func (m *Model) WhereNotNull(columns ...string) *Model { - model := m - for _, column := range columns { - model = m.Wheref(`%s IS NOT NULL`, m.QuoteWord(column)) - } - return model + return m.callWhereBuilder(m.whereBuilder.WhereNotNull(columns...)) } diff --git a/database/gdb/gdb_model_where_prefix.go b/database/gdb/gdb_model_where_prefix.go index 382a0b1a797..1ec8a466a81 100644 --- a/database/gdb/gdb_model_where_prefix.go +++ b/database/gdb/gdb_model_where_prefix.go @@ -7,93 +7,71 @@ package gdb // WherePrefix performs as Where, but it adds prefix to each field in where statement. -// Eg: -// WherePrefix("order", "status", "paid") => WHERE `order`.`status`='paid' -// WherePrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE `order`.`status`='paid' AND `order`.`channel`='bank' func (m *Model) WherePrefix(prefix string, where interface{}, args ...interface{}) *Model { - model := m.getModel() - if model.whereHolder == nil { - model.whereHolder = make([]ModelWhereHolder, 0) - } - model.whereHolder = append(model.whereHolder, ModelWhereHolder{ - Type: whereHolderTypeDefault, - Operator: whereHolderOperatorWhere, - Where: where, - Args: args, - Prefix: prefix, - }) - return model + return m.callWhereBuilder(m.whereBuilder.WherePrefix(prefix, where, args...)) } // WherePrefixLT builds `prefix.column < value` statement. func (m *Model) WherePrefixLT(prefix string, column string, value interface{}) *Model { - return m.Wheref(`%s.%s < ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WherePrefixLT(prefix, column, value)) } // WherePrefixLTE builds `prefix.column <= value` statement. func (m *Model) WherePrefixLTE(prefix string, column string, value interface{}) *Model { - return m.Wheref(`%s.%s <= ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WherePrefixLTE(prefix, column, value)) } // WherePrefixGT builds `prefix.column > value` statement. func (m *Model) WherePrefixGT(prefix string, column string, value interface{}) *Model { - return m.Wheref(`%s.%s > ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WherePrefixGT(prefix, column, value)) } // WherePrefixGTE builds `prefix.column >= value` statement. func (m *Model) WherePrefixGTE(prefix string, column string, value interface{}) *Model { - return m.Wheref(`%s.%s >= ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WherePrefixGTE(prefix, column, value)) } // WherePrefixBetween builds `prefix.column BETWEEN min AND max` statement. func (m *Model) WherePrefixBetween(prefix string, column string, min, max interface{}) *Model { - return m.Wheref(`%s.%s BETWEEN ? AND ?`, m.QuoteWord(prefix), m.QuoteWord(column), min, max) + return m.callWhereBuilder(m.whereBuilder.WherePrefixBetween(prefix, column, min, max)) } // WherePrefixLike builds `prefix.column LIKE like` statement. func (m *Model) WherePrefixLike(prefix string, column string, like interface{}) *Model { - return m.Wheref(`%s.%s LIKE ?`, m.QuoteWord(prefix), m.QuoteWord(column), like) + return m.callWhereBuilder(m.whereBuilder.WherePrefixLike(prefix, column, like)) } // WherePrefixIn builds `prefix.column IN (in)` statement. func (m *Model) WherePrefixIn(prefix string, column string, in interface{}) *Model { - return m.doWherefType(whereHolderTypeIn, `%s.%s IN (?)`, m.QuoteWord(prefix), m.QuoteWord(column), in) + return m.callWhereBuilder(m.whereBuilder.WherePrefixIn(prefix, column, in)) } // WherePrefixNull builds `prefix.columns[0] IS NULL AND prefix.columns[1] IS NULL ...` statement. func (m *Model) WherePrefixNull(prefix string, columns ...string) *Model { - model := m - for _, column := range columns { - model = m.Wheref(`%s.%s IS NULL`, m.QuoteWord(prefix), m.QuoteWord(column)) - } - return model + return m.callWhereBuilder(m.whereBuilder.WherePrefixNull(prefix, columns...)) } // WherePrefixNotBetween builds `prefix.column NOT BETWEEN min AND max` statement. func (m *Model) WherePrefixNotBetween(prefix string, column string, min, max interface{}) *Model { - return m.Wheref(`%s.%s NOT BETWEEN ? AND ?`, m.QuoteWord(prefix), m.QuoteWord(column), min, max) + return m.callWhereBuilder(m.whereBuilder.WherePrefixNotBetween(prefix, column, min, max)) } // WherePrefixNotLike builds `prefix.column NOT LIKE like` statement. func (m *Model) WherePrefixNotLike(prefix string, column string, like interface{}) *Model { - return m.Wheref(`%s.%s NOT LIKE ?`, m.QuoteWord(prefix), m.QuoteWord(column), like) + return m.callWhereBuilder(m.whereBuilder.WherePrefixNotLike(prefix, column, like)) } // WherePrefixNot builds `prefix.column != value` statement. func (m *Model) WherePrefixNot(prefix string, column string, value interface{}) *Model { - return m.Wheref(`%s.%s != ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WherePrefixNot(prefix, column, value)) } // WherePrefixNotIn builds `prefix.column NOT IN (in)` statement. func (m *Model) WherePrefixNotIn(prefix string, column string, in interface{}) *Model { - return m.doWherefType(whereHolderTypeIn, `%s.%s NOT IN (?)`, m.QuoteWord(prefix), m.QuoteWord(column), in) + return m.callWhereBuilder(m.whereBuilder.WherePrefixNot(prefix, column, in)) } // WherePrefixNotNull builds `prefix.columns[0] IS NOT NULL AND prefix.columns[1] IS NOT NULL ...` statement. func (m *Model) WherePrefixNotNull(prefix string, columns ...string) *Model { - model := m - for _, column := range columns { - model = m.Wheref(`%s.%s IS NOT NULL`, m.QuoteWord(prefix), m.QuoteWord(column)) - } - return model + return m.callWhereBuilder(m.whereBuilder.WherePrefixNotNull(prefix, columns...)) } diff --git a/database/gdb/gdb_model_whereor.go b/database/gdb/gdb_model_whereor.go index 3d288459e8f..9dcf14ae6cc 100644 --- a/database/gdb/gdb_model_whereor.go +++ b/database/gdb/gdb_model_whereor.go @@ -6,113 +6,72 @@ package gdb -import ( - "fmt" - - "github.com/gogf/gf/v2/text/gstr" -) - -// WhereOr adds "OR" condition to the where statement. -func (m *Model) doWhereOrType(t string, where interface{}, args ...interface{}) *Model { - model := m.getModel() - if model.whereHolder == nil { - model.whereHolder = make([]ModelWhereHolder, 0) - } - model.whereHolder = append(model.whereHolder, ModelWhereHolder{ - Type: t, - Operator: whereHolderOperatorOr, - Where: where, - Args: args, - }) - return model -} - -// WhereOrf builds `OR` condition string using fmt.Sprintf and arguments. -func (m *Model) doWhereOrfType(t string, format string, args ...interface{}) *Model { - var ( - placeHolderCount = gstr.Count(format, "?") - conditionStr = fmt.Sprintf(format, args[:len(args)-placeHolderCount]...) - ) - return m.doWhereOrType(t, conditionStr, args[len(args)-placeHolderCount:]...) -} - // WhereOr adds "OR" condition to the where statement. func (m *Model) WhereOr(where interface{}, args ...interface{}) *Model { - return m.doWhereOrType(``, where, args...) + return m.callWhereBuilder(m.whereBuilder.WhereOr(where, args...)) } // WhereOrf builds `OR` condition string using fmt.Sprintf and arguments. -// Eg: -// WhereOrf(`amount WHERE xxx OR `amount`<100 and status='paid' -// WhereOrf(`amount<%d and status=%s`, 100, "paid") => WHERE xxx OR `amount`<100 and status='paid' func (m *Model) WhereOrf(format string, args ...interface{}) *Model { - return m.doWhereOrfType(``, format, args...) + return m.callWhereBuilder(m.whereBuilder.WhereOrf(format, args...)) } // WhereOrLT builds `column < value` statement in `OR` conditions.. func (m *Model) WhereOrLT(column string, value interface{}) *Model { - return m.WhereOrf(`%s < ?`, column, value) + return m.callWhereBuilder(m.whereBuilder.WhereOrLT(column, value)) } // WhereOrLTE builds `column <= value` statement in `OR` conditions.. func (m *Model) WhereOrLTE(column string, value interface{}) *Model { - return m.WhereOrf(`%s <= ?`, column, value) + return m.callWhereBuilder(m.whereBuilder.WhereOrLTE(column, value)) } // WhereOrGT builds `column > value` statement in `OR` conditions.. func (m *Model) WhereOrGT(column string, value interface{}) *Model { - return m.WhereOrf(`%s > ?`, column, value) + return m.callWhereBuilder(m.whereBuilder.WhereOrGT(column, value)) } // WhereOrGTE builds `column >= value` statement in `OR` conditions.. func (m *Model) WhereOrGTE(column string, value interface{}) *Model { - return m.WhereOrf(`%s >= ?`, column, value) + return m.callWhereBuilder(m.whereBuilder.WhereOrGTE(column, value)) } // WhereOrBetween builds `column BETWEEN min AND max` statement in `OR` conditions. func (m *Model) WhereOrBetween(column string, min, max interface{}) *Model { - return m.WhereOrf(`%s BETWEEN ? AND ?`, m.QuoteWord(column), min, max) + return m.callWhereBuilder(m.whereBuilder.WhereOrBetween(column, min, max)) } // WhereOrLike builds `column LIKE like` statement in `OR` conditions. func (m *Model) WhereOrLike(column string, like interface{}) *Model { - return m.WhereOrf(`%s LIKE ?`, m.QuoteWord(column), like) + return m.callWhereBuilder(m.whereBuilder.WhereOrLike(column, like)) } // WhereOrIn builds `column IN (in)` statement in `OR` conditions. func (m *Model) WhereOrIn(column string, in interface{}) *Model { - return m.doWhereOrfType(whereHolderTypeIn, `%s IN (?)`, m.QuoteWord(column), in) + return m.callWhereBuilder(m.whereBuilder.WhereOrIn(column, in)) } // WhereOrNull builds `columns[0] IS NULL OR columns[1] IS NULL ...` statement in `OR` conditions. func (m *Model) WhereOrNull(columns ...string) *Model { - model := m - for _, column := range columns { - model = m.WhereOrf(`%s IS NULL`, m.QuoteWord(column)) - } - return model + return m.callWhereBuilder(m.whereBuilder.WhereOrNull(columns...)) } // WhereOrNotBetween builds `column NOT BETWEEN min AND max` statement in `OR` conditions. func (m *Model) WhereOrNotBetween(column string, min, max interface{}) *Model { - return m.WhereOrf(`%s NOT BETWEEN ? AND ?`, m.QuoteWord(column), min, max) + return m.callWhereBuilder(m.whereBuilder.WhereOrNotBetween(column, min, max)) } // WhereOrNotLike builds `column NOT LIKE like` statement in `OR` conditions. func (m *Model) WhereOrNotLike(column string, like interface{}) *Model { - return m.WhereOrf(`%s NOT LIKE ?`, m.QuoteWord(column), like) + return m.callWhereBuilder(m.whereBuilder.WhereOrNotLike(column, like)) } // WhereOrNotIn builds `column NOT IN (in)` statement. func (m *Model) WhereOrNotIn(column string, in interface{}) *Model { - return m.doWhereOrfType(whereHolderTypeIn, `%s NOT IN (?)`, m.QuoteWord(column), in) + return m.callWhereBuilder(m.whereBuilder.WhereOrNotIn(column, in)) } // WhereOrNotNull builds `columns[0] IS NOT NULL OR columns[1] IS NOT NULL ...` statement in `OR` conditions. func (m *Model) WhereOrNotNull(columns ...string) *Model { - model := m - for _, column := range columns { - model = m.WhereOrf(`%s IS NOT NULL`, m.QuoteWord(column)) - } - return model + return m.callWhereBuilder(m.whereBuilder.WhereOrNotNull(columns...)) } diff --git a/database/gdb/gdb_model_whereor_prefix.go b/database/gdb/gdb_model_whereor_prefix.go index 7230895cb49..ebf5ad575ee 100644 --- a/database/gdb/gdb_model_whereor_prefix.go +++ b/database/gdb/gdb_model_whereor_prefix.go @@ -7,88 +7,66 @@ package gdb // WhereOrPrefix performs as WhereOr, but it adds prefix to each field in where statement. -// Eg: -// WhereOrPrefix("order", "status", "paid") => WHERE xxx OR (`order`.`status`='paid') -// WhereOrPrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE xxx OR (`order`.`status`='paid' AND `order`.`channel`='bank') func (m *Model) WhereOrPrefix(prefix string, where interface{}, args ...interface{}) *Model { - model := m.getModel() - if model.whereHolder == nil { - model.whereHolder = make([]ModelWhereHolder, 0) - } - model.whereHolder = append(model.whereHolder, ModelWhereHolder{ - Type: whereHolderTypeDefault, - Operator: whereHolderOperatorOr, - Where: where, - Args: args, - Prefix: prefix, - }) - return model + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefix(prefix, where, args...)) } // WhereOrPrefixLT builds `prefix.column < value` statement in `OR` conditions.. func (m *Model) WhereOrPrefixLT(prefix string, column string, value interface{}) *Model { - return m.WhereOrf(`%s.%s < ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixLT(prefix, column, value)) } // WhereOrPrefixLTE builds `prefix.column <= value` statement in `OR` conditions.. func (m *Model) WhereOrPrefixLTE(prefix string, column string, value interface{}) *Model { - return m.WhereOrf(`%s.%s <= ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixLTE(prefix, column, value)) } // WhereOrPrefixGT builds `prefix.column > value` statement in `OR` conditions.. func (m *Model) WhereOrPrefixGT(prefix string, column string, value interface{}) *Model { - return m.WhereOrf(`%s.%s > ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixGT(prefix, column, value)) } // WhereOrPrefixGTE builds `prefix.column >= value` statement in `OR` conditions.. func (m *Model) WhereOrPrefixGTE(prefix string, column string, value interface{}) *Model { - return m.WhereOrf(`%s.%s >= ?`, m.QuoteWord(prefix), m.QuoteWord(column), value) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixGTE(prefix, column, value)) } // WhereOrPrefixBetween builds `prefix.column BETWEEN min AND max` statement in `OR` conditions. func (m *Model) WhereOrPrefixBetween(prefix string, column string, min, max interface{}) *Model { - return m.WhereOrf(`%s.%s BETWEEN ? AND ?`, m.QuoteWord(prefix), m.QuoteWord(column), min, max) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixBetween(prefix, column, min, max)) } // WhereOrPrefixLike builds `prefix.column LIKE like` statement in `OR` conditions. func (m *Model) WhereOrPrefixLike(prefix string, column string, like interface{}) *Model { - return m.WhereOrf(`%s.%s LIKE ?`, m.QuoteWord(prefix), m.QuoteWord(column), like) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixLike(prefix, column, like)) } // WhereOrPrefixIn builds `prefix.column IN (in)` statement in `OR` conditions. func (m *Model) WhereOrPrefixIn(prefix string, column string, in interface{}) *Model { - return m.doWhereOrfType(whereHolderTypeIn, `%s.%s IN (?)`, m.QuoteWord(prefix), m.QuoteWord(column), in) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixIn(prefix, column, in)) } // WhereOrPrefixNull builds `prefix.columns[0] IS NULL OR prefix.columns[1] IS NULL ...` statement in `OR` conditions. func (m *Model) WhereOrPrefixNull(prefix string, columns ...string) *Model { - model := m - for _, column := range columns { - model = m.WhereOrf(`%s.%s IS NULL`, m.QuoteWord(prefix), m.QuoteWord(column)) - } - return model + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNull(prefix, columns...)) } // WhereOrPrefixNotBetween builds `prefix.column NOT BETWEEN min AND max` statement in `OR` conditions. func (m *Model) WhereOrPrefixNotBetween(prefix string, column string, min, max interface{}) *Model { - return m.WhereOrf(`%s.%s NOT BETWEEN ? AND ?`, m.QuoteWord(prefix), m.QuoteWord(column), min, max) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNotBetween(prefix, column, min, max)) } // WhereOrPrefixNotLike builds `prefix.column NOT LIKE like` statement in `OR` conditions. func (m *Model) WhereOrPrefixNotLike(prefix string, column string, like interface{}) *Model { - return m.WhereOrf(`%s.%s NOT LIKE ?`, m.QuoteWord(prefix), m.QuoteWord(column), like) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNotLike(prefix, column, like)) } // WhereOrPrefixNotIn builds `prefix.column NOT IN (in)` statement. func (m *Model) WhereOrPrefixNotIn(prefix string, column string, in interface{}) *Model { - return m.doWhereOrfType(whereHolderTypeIn, `%s.%s NOT IN (?)`, m.QuoteWord(prefix), m.QuoteWord(column), in) + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNotIn(prefix, column, in)) } // WhereOrPrefixNotNull builds `prefix.columns[0] IS NOT NULL OR prefix.columns[1] IS NOT NULL ...` statement in `OR` conditions. func (m *Model) WhereOrPrefixNotNull(prefix string, columns ...string) *Model { - model := m - for _, column := range columns { - model = m.WhereOrf(`%s.%s IS NOT NULL`, m.QuoteWord(prefix), m.QuoteWord(column)) - } - return model + return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNotNull(prefix, columns...)) } From cb63a0e0f75c6b3dead146ee6b45d846f24231a5 Mon Sep 17 00:00:00 2001 From: John Guo Date: Fri, 6 May 2022 10:34:08 +0800 Subject: [PATCH 15/70] comment updates for package clilckhouse --- contrib/drivers/clickhouse/clickhouse.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/drivers/clickhouse/clickhouse.go b/contrib/drivers/clickhouse/clickhouse.go index cc54a65a03d..0af84eaea98 100644 --- a/contrib/drivers/clickhouse/clickhouse.go +++ b/contrib/drivers/clickhouse/clickhouse.go @@ -216,10 +216,10 @@ func (d *Driver) DoFilter( ctx context.Context, link gdb.Link, originSql string, args []interface{}, ) (newSql string, newArgs []interface{}, err error) { // It replaces STD SQL to Clickhouse SQL grammar. - // MySQL eg: UPDATE visits SET xxx - // Clickhouse eg: ALTER TABLE visits UPDATE xxx - // MySQL eg: DELETE FROM VISIT - // Clickhouse eg: ALTER TABLE VISIT DELETE WHERE filter_expr + // MySQL eg: UPDATE `table` SET xxx + // Clickhouse eg: ALTER TABLE `table` UPDATE xxx + // MySQL eg: DELETE FROM `table` + // Clickhouse eg: ALTER TABLE `table` DELETE WHERE filter_expr result, err := gregex.MatchString("(?i)^UPDATE|DELETE", originSql) if err != nil { return "", nil, err From bcf06223210841b402b35b53cee5e7d07e87f8ac Mon Sep 17 00:00:00 2001 From: John Guo Date: Fri, 6 May 2022 22:21:43 +0800 Subject: [PATCH 16/70] improve WhereBuilder for package gdb --- database/gdb/gdb_model.go | 5 +- database/gdb/gdb_model_builder.go | 59 +++++-------------- database/gdb/gdb_model_builder_where.go | 24 ++++++-- database/gdb/gdb_model_select.go | 18 ++++++ ...core_sharding.go => gdb_model_sharding.go} | 0 .../gdb_z_mysql_feature_model_builder_test.go | 46 +++++++++++++++ 6 files changed, 103 insertions(+), 49 deletions(-) rename database/gdb/{gdb_core_sharding.go => gdb_model_sharding.go} (100%) create mode 100644 database/gdb/gdb_z_mysql_feature_model_builder_test.go diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 4769aaa4d38..7ce22934634 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -136,6 +136,9 @@ func (c *Core) Model(tableNameQueryOrStruct ...interface{}) *Model { extraArgs: extraArgs, } m.whereBuilder = m.Builder() + // Assign the safe attribute of WhereBuilder to nil, + // to make it use the safe attribute of its bound model. + m.whereBuilder.safe = nil if defaultModelSafe { m.safe = true } @@ -262,7 +265,7 @@ func (m *Model) Clone() *Model { // Basic attributes copy. *newModel = *m // WhereBuilder copy, note the attribute pointer. - newModel.whereBuilder = m.whereBuilder.Clone() + newModel.whereBuilder = m.whereBuilder.clone() newModel.whereBuilder.model = newModel // Shallow copy slice attributes. if n := len(m.extraArgs); n > 0 { diff --git a/database/gdb/gdb_model_builder.go b/database/gdb/gdb_model_builder.go index 0a1ccd6ffa4..7687da67560 100644 --- a/database/gdb/gdb_model_builder.go +++ b/database/gdb/gdb_model_builder.go @@ -8,12 +8,11 @@ package gdb import ( "fmt" - - "github.com/gogf/gf/v2/text/gstr" ) type WhereBuilder struct { - model *Model // Bound to parent model. + safe *bool // If nil, it uses the safe attribute of its model. + model *Model // A WhereBuilder should be bound to certain Model. whereHolder []WhereHolder // Condition strings for where operation. } @@ -27,7 +26,10 @@ type WhereHolder struct { } func (m *Model) Builder() *WhereBuilder { + // The WhereBuilder is safe in default when it is created using Builder(). + var isSafe = true b := &WhereBuilder{ + safe: &isSafe, model: m, whereHolder: make([]WhereHolder, 0), } @@ -37,15 +39,22 @@ func (m *Model) Builder() *WhereBuilder { // getBuilder creates and returns a cloned WhereBuilder of current WhereBuilder if `safe` is true, // or else it returns the current WhereBuilder. func (b *WhereBuilder) getBuilder() *WhereBuilder { - if !b.model.safe { + var isSafe bool + if b.safe != nil { + isSafe = *b.safe + } else { + isSafe = b.model.safe + } + if !isSafe { return b } else { - return b.Clone() + return b.clone() } } -func (b *WhereBuilder) Clone() *WhereBuilder { +func (b *WhereBuilder) clone() *WhereBuilder { newBuilder := b.model.Builder() + newBuilder.safe = b.safe newBuilder.whereHolder = make([]WhereHolder, len(b.whereHolder)) copy(newBuilder.whereHolder, b.whereHolder) return newBuilder @@ -63,24 +72,7 @@ func (b *WhereBuilder) Build() (conditionWhere string, conditionArgs []interface holder.Prefix = autoPrefix } switch holder.Operator { - case whereHolderOperatorWhere: - if conditionWhere == "" { - newWhere, newArgs := formatWhereHolder(ctx, b.model.db, formatWhereHolderInput{ - WhereHolder: holder, - OmitNil: b.model.option&optionOmitNilWhere > 0, - OmitEmpty: b.model.option&optionOmitEmptyWhere > 0, - Schema: b.model.schema, - Table: tableForMappingAndFiltering, - }) - if len(newWhere) > 0 { - conditionWhere = newWhere - conditionArgs = newArgs - } - continue - } - fallthrough - - case whereHolderOperatorAnd: + case whereHolderOperatorWhere, whereHolderOperatorAnd: newWhere, newArgs := formatWhereHolder(ctx, b.model.db, formatWhereHolderInput{ WhereHolder: holder, OmitNil: b.model.option&optionOmitNilWhere > 0, @@ -120,24 +112,5 @@ func (b *WhereBuilder) Build() (conditionWhere string, conditionArgs []interface } } } - // Soft deletion. - softDeletingCondition := b.model.getConditionForSoftDeleting() - if b.model.rawSql != "" && conditionWhere != "" { - if gstr.ContainsI(b.model.rawSql, " WHERE ") { - conditionWhere = " AND " + conditionWhere - } else { - conditionWhere = " WHERE " + conditionWhere - } - } else if !b.model.unscoped && softDeletingCondition != "" { - if conditionWhere == "" { - conditionWhere = fmt.Sprintf(` WHERE %s`, softDeletingCondition) - } else { - conditionWhere = fmt.Sprintf(` WHERE (%s) AND %s`, conditionWhere, softDeletingCondition) - } - } else { - if conditionWhere != "" { - conditionWhere = " WHERE " + conditionWhere - } - } return } diff --git a/database/gdb/gdb_model_builder_where.go b/database/gdb/gdb_model_builder_where.go index 5803f8d8297..0a4e45de7a9 100644 --- a/database/gdb/gdb_model_builder_where.go +++ b/database/gdb/gdb_model_builder_where.go @@ -15,20 +15,20 @@ import ( // doWhereType sets the condition statement for the model. The parameter `where` can be type of // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, // multiple conditions will be joined into where statement using "AND". -func (b *WhereBuilder) doWhereType(t string, where interface{}, args ...interface{}) *WhereBuilder { +func (b *WhereBuilder) doWhereType(whereType string, where interface{}, args ...interface{}) *WhereBuilder { builder := b.getBuilder() if builder.whereHolder == nil { builder.whereHolder = make([]WhereHolder, 0) } - if t == "" { + if whereType == "" { if len(args) == 0 { - t = whereHolderTypeNoArgs + whereType = whereHolderTypeNoArgs } else { - t = whereHolderTypeDefault + whereType = whereHolderTypeDefault } } builder.whereHolder = append(builder.whereHolder, WhereHolder{ - Type: t, + Type: whereType, Operator: whereHolderOperatorWhere, Where: where, Args: args, @@ -59,6 +59,20 @@ func (b *WhereBuilder) doWherefType(t string, format string, args ...interface{} // Where("age IN(?,?)", 18, 50) // Where(User{ Id : 1, UserName : "john"}). func (b *WhereBuilder) Where(where interface{}, args ...interface{}) *WhereBuilder { + var builder *WhereBuilder + switch v := where.(type) { + case WhereBuilder: + builder = &v + case *WhereBuilder: + builder = v + } + if builder != nil { + conditionWhere, conditionArgs := builder.Build() + if len(b.whereHolder) == 0 { + conditionWhere = "(" + conditionWhere + ")" + } + return b.doWhereType(``, conditionWhere, conditionArgs...) + } return b.doWhereType(``, where, args...) } diff --git a/database/gdb/gdb_model_select.go b/database/gdb/gdb_model_select.go index b7f782f4ab1..d39fc4728ab 100644 --- a/database/gdb/gdb_model_select.go +++ b/database/gdb/gdb_model_select.go @@ -616,6 +616,24 @@ func (m *Model) formatCondition(ctx context.Context, limit1 bool, isCountStateme } // WHERE conditionWhere, conditionArgs = m.whereBuilder.Build() + softDeletingCondition := m.getConditionForSoftDeleting() + if m.rawSql != "" && conditionWhere != "" { + if gstr.ContainsI(m.rawSql, " WHERE ") { + conditionWhere = " AND " + conditionWhere + } else { + conditionWhere = " WHERE " + conditionWhere + } + } else if !m.unscoped && softDeletingCondition != "" { + if conditionWhere == "" { + conditionWhere = fmt.Sprintf(` WHERE %s`, softDeletingCondition) + } else { + conditionWhere = fmt.Sprintf(` WHERE (%s) AND %s`, conditionWhere, softDeletingCondition) + } + } else { + if conditionWhere != "" { + conditionWhere = " WHERE " + conditionWhere + } + } // HAVING. if len(m.having) > 0 { havingHolder := WhereHolder{ diff --git a/database/gdb/gdb_core_sharding.go b/database/gdb/gdb_model_sharding.go similarity index 100% rename from database/gdb/gdb_core_sharding.go rename to database/gdb/gdb_model_sharding.go diff --git a/database/gdb/gdb_z_mysql_feature_model_builder_test.go b/database/gdb/gdb_z_mysql_feature_model_builder_test.go new file mode 100644 index 00000000000..43e319731de --- /dev/null +++ b/database/gdb/gdb_z_mysql_feature_model_builder_test.go @@ -0,0 +1,46 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package gdb_test + +import ( + "testing" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/test/gtest" +) + +func Test_Model_Builder(t *testing.T) { + table := createInitTable() + defer dropTable(table) + + gtest.C(t, func(t *gtest.T) { + m := db.Model(table) + b := m.Builder() + + all, err := m.Where( + b.Where("id", g.Slice{1, 2, 3}).WhereOr("id", g.Slice{4, 5, 6}), + ).All() + t.AssertNil(err) + t.Assert(len(all), 6) + }) + + gtest.C(t, func(t *gtest.T) { + m := db.Model(table) + b := m.Builder() + + all, err := m.Where( + b.Where("id", g.Slice{1, 2, 3}).WhereOr("id", g.Slice{4, 5, 6}), + ).Where( + b.Where("id", g.Slice{2, 3}).WhereOr("id", g.Slice{5, 6}), + ).Where( + b.Where("id", g.Slice{3}).Where("id", g.Slice{1, 2, 3}), + ).All() + t.AssertNil(err) + t.Assert(len(all), 1) + }) + +} From 87506afbe0c08ddfa4e0ab1a6b0bd18ed285e30b Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 7 May 2022 14:26:56 +0800 Subject: [PATCH 17/70] improve WhereBuilder feature for package gdb --- database/gdb/gdb_model.go | 10 ++++----- database/gdb/gdb_model_builder.go | 22 +++++++++++++++++-- database/gdb/gdb_model_builder_where.go | 16 ++------------ .../gdb/gdb_model_builder_where_prefix.go | 2 ++ database/gdb/gdb_model_builder_whereor.go | 2 ++ .../gdb/gdb_model_builder_whereor_prefix.go | 2 ++ 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 7ce22934634..70429a33975 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -136,9 +136,7 @@ func (c *Core) Model(tableNameQueryOrStruct ...interface{}) *Model { extraArgs: extraArgs, } m.whereBuilder = m.Builder() - // Assign the safe attribute of WhereBuilder to nil, - // to make it use the safe attribute of its bound model. - m.whereBuilder.safe = nil + m.whereBuilder.safe = &m.safe if defaultModelSafe { m.safe = true } @@ -253,8 +251,8 @@ func (m *Model) Schema(schema string) *Model { return model } -// Clone creates and returns a new model which is a clone of current model. -// Note that it uses deep-copy for the clone. +// Clone creates and returns a new model which is a Clone of current model. +// Note that it uses deep-copy for the Clone. func (m *Model) Clone() *Model { newModel := (*Model)(nil) if m.tx != nil { @@ -265,7 +263,7 @@ func (m *Model) Clone() *Model { // Basic attributes copy. *newModel = *m // WhereBuilder copy, note the attribute pointer. - newModel.whereBuilder = m.whereBuilder.clone() + newModel.whereBuilder = m.whereBuilder.Clone() newModel.whereBuilder.model = newModel // Shallow copy slice attributes. if n := len(m.extraArgs); n > 0 { diff --git a/database/gdb/gdb_model_builder.go b/database/gdb/gdb_model_builder.go index 7687da67560..a271e33f51a 100644 --- a/database/gdb/gdb_model_builder.go +++ b/database/gdb/gdb_model_builder.go @@ -48,11 +48,11 @@ func (b *WhereBuilder) getBuilder() *WhereBuilder { if !isSafe { return b } else { - return b.clone() + return b.Clone() } } -func (b *WhereBuilder) clone() *WhereBuilder { +func (b *WhereBuilder) Clone() *WhereBuilder { newBuilder := b.model.Builder() newBuilder.safe = b.safe newBuilder.whereHolder = make([]WhereHolder, len(b.whereHolder)) @@ -114,3 +114,21 @@ func (b *WhereBuilder) Build() (conditionWhere string, conditionArgs []interface } return } + +func (b *WhereBuilder) convertWrappedBuilder(where interface{}, args []interface{}) (newWhere interface{}, newArgs []interface{}) { + var builder *WhereBuilder + switch v := where.(type) { + case WhereBuilder: + builder = &v + case *WhereBuilder: + builder = v + } + if builder != nil { + conditionWhere, conditionArgs := builder.Build() + if len(b.whereHolder) == 0 { + conditionWhere = "(" + conditionWhere + ")" + } + return conditionWhere, conditionArgs + } + return where, args +} diff --git a/database/gdb/gdb_model_builder_where.go b/database/gdb/gdb_model_builder_where.go index 0a4e45de7a9..4980175c0bf 100644 --- a/database/gdb/gdb_model_builder_where.go +++ b/database/gdb/gdb_model_builder_where.go @@ -16,6 +16,8 @@ import ( // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, // multiple conditions will be joined into where statement using "AND". func (b *WhereBuilder) doWhereType(whereType string, where interface{}, args ...interface{}) *WhereBuilder { + where, args = b.convertWrappedBuilder(where, args) + builder := b.getBuilder() if builder.whereHolder == nil { builder.whereHolder = make([]WhereHolder, 0) @@ -59,20 +61,6 @@ func (b *WhereBuilder) doWherefType(t string, format string, args ...interface{} // Where("age IN(?,?)", 18, 50) // Where(User{ Id : 1, UserName : "john"}). func (b *WhereBuilder) Where(where interface{}, args ...interface{}) *WhereBuilder { - var builder *WhereBuilder - switch v := where.(type) { - case WhereBuilder: - builder = &v - case *WhereBuilder: - builder = v - } - if builder != nil { - conditionWhere, conditionArgs := builder.Build() - if len(b.whereHolder) == 0 { - conditionWhere = "(" + conditionWhere + ")" - } - return b.doWhereType(``, conditionWhere, conditionArgs...) - } return b.doWhereType(``, where, args...) } diff --git a/database/gdb/gdb_model_builder_where_prefix.go b/database/gdb/gdb_model_builder_where_prefix.go index 7cc189901b1..5fbebb6a0e6 100644 --- a/database/gdb/gdb_model_builder_where_prefix.go +++ b/database/gdb/gdb_model_builder_where_prefix.go @@ -11,6 +11,8 @@ package gdb // WherePrefix("order", "status", "paid") => WHERE `order`.`status`='paid' // WherePrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE `order`.`status`='paid' AND `order`.`channel`='bank' func (b *WhereBuilder) WherePrefix(prefix string, where interface{}, args ...interface{}) *WhereBuilder { + where, args = b.convertWrappedBuilder(where, args) + builder := b.getBuilder() if builder.whereHolder == nil { builder.whereHolder = make([]WhereHolder, 0) diff --git a/database/gdb/gdb_model_builder_whereor.go b/database/gdb/gdb_model_builder_whereor.go index 993c4def37f..ebd5157b3e6 100644 --- a/database/gdb/gdb_model_builder_whereor.go +++ b/database/gdb/gdb_model_builder_whereor.go @@ -14,6 +14,8 @@ import ( // WhereOr adds "OR" condition to the where statement. func (b *WhereBuilder) doWhereOrType(t string, where interface{}, args ...interface{}) *WhereBuilder { + where, args = b.convertWrappedBuilder(where, args) + builder := b.getBuilder() if builder.whereHolder == nil { builder.whereHolder = make([]WhereHolder, 0) diff --git a/database/gdb/gdb_model_builder_whereor_prefix.go b/database/gdb/gdb_model_builder_whereor_prefix.go index c720b7c3f1c..102c4936ac5 100644 --- a/database/gdb/gdb_model_builder_whereor_prefix.go +++ b/database/gdb/gdb_model_builder_whereor_prefix.go @@ -11,6 +11,8 @@ package gdb // WhereOrPrefix("order", "status", "paid") => WHERE xxx OR (`order`.`status`='paid') // WhereOrPrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE xxx OR (`order`.`status`='paid' AND `order`.`channel`='bank') func (b *WhereBuilder) WhereOrPrefix(prefix string, where interface{}, args ...interface{}) *WhereBuilder { + where, args = b.convertWrappedBuilder(where, args) + builder := b.getBuilder() builder.whereHolder = append(builder.whereHolder, WhereHolder{ Type: whereHolderTypeDefault, From 547cff84cd6684b5a867adce6ec778ac7b0537d7 Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 7 May 2022 15:11:31 +0800 Subject: [PATCH 18/70] improve WhereBuilder feature for package gdb --- database/gdb/gdb_model.go | 3 ++ database/gdb/gdb_model_builder.go | 7 ++++- database/gdb/gdb_model_builder_where.go | 2 +- .../gdb/gdb_model_builder_where_prefix.go | 2 +- database/gdb/gdb_model_builder_whereor.go | 2 +- .../gdb/gdb_model_builder_whereor_prefix.go | 2 +- database/gdb/gdb_model_where.go | 30 +++++++++++++++++++ database/gdb/gdb_model_where_prefix.go | 14 +++++++++ database/gdb/gdb_model_whereor.go | 14 +++++++++ database/gdb/gdb_model_whereor_prefix.go | 13 ++++++++ .../gdb_z_mysql_feature_model_builder_test.go | 17 +++++++++++ 11 files changed, 101 insertions(+), 5 deletions(-) diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 70429a33975..98010a07004 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -17,6 +17,7 @@ import ( // Model is core struct implementing the DAO for ORM. type Model struct { + *modelWhereBuilder db DB // Underlying DB interface. tx *TX // Underlying TX interface. rawSql string // rawSql is the raw SQL string which marks a raw SQL based Model not a table based Model. @@ -52,6 +53,8 @@ type Model struct { onDuplicateEx interface{} // onDuplicateEx is used for excluding some columns ON "DUPLICATE KEY UPDATE" statement. } +type modelWhereBuilder = WhereBuilder + // ModelHandler is a function that handles given Model and returns a new Model that is custom modified. type ModelHandler func(m *Model) *Model diff --git a/database/gdb/gdb_model_builder.go b/database/gdb/gdb_model_builder.go index a271e33f51a..83a95ade559 100644 --- a/database/gdb/gdb_model_builder.go +++ b/database/gdb/gdb_model_builder.go @@ -10,6 +10,7 @@ import ( "fmt" ) +// WhereBuilder holds multiple where conditions in a group. type WhereBuilder struct { safe *bool // If nil, it uses the safe attribute of its model. model *Model // A WhereBuilder should be bound to certain Model. @@ -25,6 +26,7 @@ type WhereHolder struct { Prefix string // Field prefix, eg: "user.", "order.". } +// Builder creates and returns a WhereBuilder. func (m *Model) Builder() *WhereBuilder { // The WhereBuilder is safe in default when it is created using Builder(). var isSafe = true @@ -52,6 +54,7 @@ func (b *WhereBuilder) getBuilder() *WhereBuilder { } } +// Clone clones and returns a WhereBuilder that is a copy of current one. func (b *WhereBuilder) Clone() *WhereBuilder { newBuilder := b.model.Builder() newBuilder.safe = b.safe @@ -60,6 +63,7 @@ func (b *WhereBuilder) Clone() *WhereBuilder { return newBuilder } +// Build builds current WhereBuilder and returns the condition string and parameters. func (b *WhereBuilder) Build() (conditionWhere string, conditionArgs []interface{}) { var ( ctx = b.model.GetCtx() @@ -115,7 +119,8 @@ func (b *WhereBuilder) Build() (conditionWhere string, conditionArgs []interface return } -func (b *WhereBuilder) convertWrappedBuilder(where interface{}, args []interface{}) (newWhere interface{}, newArgs []interface{}) { +// convertWhereBuilder converts parameter `where` to condition string and parameters if `where` is also a WhereBuilder. +func (b *WhereBuilder) convertWhereBuilder(where interface{}, args []interface{}) (newWhere interface{}, newArgs []interface{}) { var builder *WhereBuilder switch v := where.(type) { case WhereBuilder: diff --git a/database/gdb/gdb_model_builder_where.go b/database/gdb/gdb_model_builder_where.go index 4980175c0bf..4ae43f856a8 100644 --- a/database/gdb/gdb_model_builder_where.go +++ b/database/gdb/gdb_model_builder_where.go @@ -16,7 +16,7 @@ import ( // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, // multiple conditions will be joined into where statement using "AND". func (b *WhereBuilder) doWhereType(whereType string, where interface{}, args ...interface{}) *WhereBuilder { - where, args = b.convertWrappedBuilder(where, args) + where, args = b.convertWhereBuilder(where, args) builder := b.getBuilder() if builder.whereHolder == nil { diff --git a/database/gdb/gdb_model_builder_where_prefix.go b/database/gdb/gdb_model_builder_where_prefix.go index 5fbebb6a0e6..eec46db1d00 100644 --- a/database/gdb/gdb_model_builder_where_prefix.go +++ b/database/gdb/gdb_model_builder_where_prefix.go @@ -11,7 +11,7 @@ package gdb // WherePrefix("order", "status", "paid") => WHERE `order`.`status`='paid' // WherePrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE `order`.`status`='paid' AND `order`.`channel`='bank' func (b *WhereBuilder) WherePrefix(prefix string, where interface{}, args ...interface{}) *WhereBuilder { - where, args = b.convertWrappedBuilder(where, args) + where, args = b.convertWhereBuilder(where, args) builder := b.getBuilder() if builder.whereHolder == nil { diff --git a/database/gdb/gdb_model_builder_whereor.go b/database/gdb/gdb_model_builder_whereor.go index ebd5157b3e6..1ab91a77c40 100644 --- a/database/gdb/gdb_model_builder_whereor.go +++ b/database/gdb/gdb_model_builder_whereor.go @@ -14,7 +14,7 @@ import ( // WhereOr adds "OR" condition to the where statement. func (b *WhereBuilder) doWhereOrType(t string, where interface{}, args ...interface{}) *WhereBuilder { - where, args = b.convertWrappedBuilder(where, args) + where, args = b.convertWhereBuilder(where, args) builder := b.getBuilder() if builder.whereHolder == nil { diff --git a/database/gdb/gdb_model_builder_whereor_prefix.go b/database/gdb/gdb_model_builder_whereor_prefix.go index 102c4936ac5..75c71c2075a 100644 --- a/database/gdb/gdb_model_builder_whereor_prefix.go +++ b/database/gdb/gdb_model_builder_whereor_prefix.go @@ -11,7 +11,7 @@ package gdb // WhereOrPrefix("order", "status", "paid") => WHERE xxx OR (`order`.`status`='paid') // WhereOrPrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE xxx OR (`order`.`status`='paid' AND `order`.`channel`='bank') func (b *WhereBuilder) WhereOrPrefix(prefix string, where interface{}, args ...interface{}) *WhereBuilder { - where, args = b.convertWrappedBuilder(where, args) + where, args = b.convertWhereBuilder(where, args) builder := b.getBuilder() builder.whereHolder = append(builder.whereHolder, WhereHolder{ diff --git a/database/gdb/gdb_model_where.go b/database/gdb/gdb_model_where.go index 09566db91f9..96ea722b6b3 100644 --- a/database/gdb/gdb_model_where.go +++ b/database/gdb/gdb_model_where.go @@ -6,84 +6,114 @@ package gdb +// callWhereBuilder creates and returns a new Model, and sets its WhereBuilder if current Model is safe. +// It sets the WhereBuilder and returns current Model directly if it is not safe. func (m *Model) callWhereBuilder(builder *WhereBuilder) *Model { model := m.getModel() model.whereBuilder = builder return model } +// Where sets the condition statement for the builder. The parameter `where` can be type of +// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, +// multiple conditions will be joined into where statement using "AND". +// See WhereBuilder.Where. func (m *Model) Where(where interface{}, args ...interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.Where(where, args...)) } +// Wheref builds condition string using fmt.Sprintf and arguments. +// Note that if the number of `args` is more than the placeholder in `format`, +// the extra `args` will be used as the where condition arguments of the Model. +// See WhereBuilder.Wheref. func (m *Model) Wheref(format string, args ...interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.Wheref(format, args...)) } +// WherePri does the same logic as Model.Where except that if the parameter `where` +// is a single condition like int/string/float/slice, it treats the condition as the primary +// key value. That is, if primary key is "id" and given `where` parameter as "123", the +// WherePri function treats the condition as "id=123", but Model.Where treats the condition +// as string "123". +// See WhereBuilder.WherePri. func (m *Model) WherePri(where interface{}, args ...interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePri(where, args...)) } +// WhereLT builds `column < value` statement. +// See WhereBuilder.WhereLT. func (m *Model) WhereLT(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereLT(column, value)) } // WhereLTE builds `column <= value` statement. +// See WhereBuilder.WhereLTE. func (m *Model) WhereLTE(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereLTE(column, value)) } // WhereGT builds `column > value` statement. +// See WhereBuilder.WhereGT. func (m *Model) WhereGT(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereGT(column, value)) } // WhereGTE builds `column >= value` statement. +// See WhereBuilder.WhereGTE. func (m *Model) WhereGTE(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereGTE(column, value)) } // WhereBetween builds `column BETWEEN min AND max` statement. +// See WhereBuilder.WhereBetween. func (m *Model) WhereBetween(column string, min, max interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereBetween(column, min, max)) } // WhereLike builds `column LIKE like` statement. +// See WhereBuilder.WhereLike. func (m *Model) WhereLike(column string, like string) *Model { return m.callWhereBuilder(m.whereBuilder.WhereLike(column, like)) } // WhereIn builds `column IN (in)` statement. +// See WhereBuilder.WhereIn. func (m *Model) WhereIn(column string, in interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereIn(column, in)) } // WhereNull builds `columns[0] IS NULL AND columns[1] IS NULL ...` statement. +// See WhereBuilder.WhereNull. func (m *Model) WhereNull(columns ...string) *Model { return m.callWhereBuilder(m.whereBuilder.WhereNull(columns...)) } // WhereNotBetween builds `column NOT BETWEEN min AND max` statement. +// See WhereBuilder.WhereNotBetween. func (m *Model) WhereNotBetween(column string, min, max interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereNotBetween(column, min, max)) } // WhereNotLike builds `column NOT LIKE like` statement. +// See WhereBuilder.WhereNotLike. func (m *Model) WhereNotLike(column string, like interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereNotLike(column, like)) } // WhereNot builds `column != value` statement. +// See WhereBuilder.WhereNot. func (m *Model) WhereNot(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereNot(column, value)) } // WhereNotIn builds `column NOT IN (in)` statement. +// See WhereBuilder.WhereNotIn. func (m *Model) WhereNotIn(column string, in interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereNotIn(column, in)) } // WhereNotNull builds `columns[0] IS NOT NULL AND columns[1] IS NOT NULL ...` statement. +// See WhereBuilder.WhereNotNull. func (m *Model) WhereNotNull(columns ...string) *Model { return m.callWhereBuilder(m.whereBuilder.WhereNotNull(columns...)) } diff --git a/database/gdb/gdb_model_where_prefix.go b/database/gdb/gdb_model_where_prefix.go index 1ec8a466a81..99dfd5dfb0a 100644 --- a/database/gdb/gdb_model_where_prefix.go +++ b/database/gdb/gdb_model_where_prefix.go @@ -7,71 +7,85 @@ package gdb // WherePrefix performs as Where, but it adds prefix to each field in where statement. +// See WhereBuilder.WherePrefix. func (m *Model) WherePrefix(prefix string, where interface{}, args ...interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefix(prefix, where, args...)) } // WherePrefixLT builds `prefix.column < value` statement. +// See WhereBuilder.WherePrefixLT. func (m *Model) WherePrefixLT(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixLT(prefix, column, value)) } // WherePrefixLTE builds `prefix.column <= value` statement. +// See WhereBuilder.WherePrefixLTE. func (m *Model) WherePrefixLTE(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixLTE(prefix, column, value)) } // WherePrefixGT builds `prefix.column > value` statement. +// See WhereBuilder.WherePrefixGT. func (m *Model) WherePrefixGT(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixGT(prefix, column, value)) } // WherePrefixGTE builds `prefix.column >= value` statement. +// See WhereBuilder.WherePrefixGTE. func (m *Model) WherePrefixGTE(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixGTE(prefix, column, value)) } // WherePrefixBetween builds `prefix.column BETWEEN min AND max` statement. +// See WhereBuilder.WherePrefixBetween. func (m *Model) WherePrefixBetween(prefix string, column string, min, max interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixBetween(prefix, column, min, max)) } // WherePrefixLike builds `prefix.column LIKE like` statement. +// See WhereBuilder.WherePrefixLike. func (m *Model) WherePrefixLike(prefix string, column string, like interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixLike(prefix, column, like)) } // WherePrefixIn builds `prefix.column IN (in)` statement. +// See WhereBuilder.WherePrefixIn. func (m *Model) WherePrefixIn(prefix string, column string, in interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixIn(prefix, column, in)) } // WherePrefixNull builds `prefix.columns[0] IS NULL AND prefix.columns[1] IS NULL ...` statement. +// See WhereBuilder.WherePrefixNull. func (m *Model) WherePrefixNull(prefix string, columns ...string) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixNull(prefix, columns...)) } // WherePrefixNotBetween builds `prefix.column NOT BETWEEN min AND max` statement. +// See WhereBuilder.WherePrefixNotBetween. func (m *Model) WherePrefixNotBetween(prefix string, column string, min, max interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixNotBetween(prefix, column, min, max)) } // WherePrefixNotLike builds `prefix.column NOT LIKE like` statement. +// See WhereBuilder.WherePrefixNotLike. func (m *Model) WherePrefixNotLike(prefix string, column string, like interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixNotLike(prefix, column, like)) } // WherePrefixNot builds `prefix.column != value` statement. +// See WhereBuilder.WherePrefixNot. func (m *Model) WherePrefixNot(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixNot(prefix, column, value)) } // WherePrefixNotIn builds `prefix.column NOT IN (in)` statement. +// See WhereBuilder.WherePrefixNotIn. func (m *Model) WherePrefixNotIn(prefix string, column string, in interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixNot(prefix, column, in)) } // WherePrefixNotNull builds `prefix.columns[0] IS NOT NULL AND prefix.columns[1] IS NOT NULL ...` statement. +// See WhereBuilder.WherePrefixNotNull. func (m *Model) WherePrefixNotNull(prefix string, columns ...string) *Model { return m.callWhereBuilder(m.whereBuilder.WherePrefixNotNull(prefix, columns...)) } diff --git a/database/gdb/gdb_model_whereor.go b/database/gdb/gdb_model_whereor.go index 9dcf14ae6cc..e9e91472322 100644 --- a/database/gdb/gdb_model_whereor.go +++ b/database/gdb/gdb_model_whereor.go @@ -7,71 +7,85 @@ package gdb // WhereOr adds "OR" condition to the where statement. +// See WhereBuilder.WhereOr. func (m *Model) WhereOr(where interface{}, args ...interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOr(where, args...)) } // WhereOrf builds `OR` condition string using fmt.Sprintf and arguments. +// See WhereBuilder.WhereOrf. func (m *Model) WhereOrf(format string, args ...interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrf(format, args...)) } // WhereOrLT builds `column < value` statement in `OR` conditions.. +// See WhereBuilder.WhereOrLT. func (m *Model) WhereOrLT(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrLT(column, value)) } // WhereOrLTE builds `column <= value` statement in `OR` conditions.. +// See WhereBuilder.WhereOrLTE. func (m *Model) WhereOrLTE(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrLTE(column, value)) } // WhereOrGT builds `column > value` statement in `OR` conditions.. +// See WhereBuilder.WhereOrGT. func (m *Model) WhereOrGT(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrGT(column, value)) } // WhereOrGTE builds `column >= value` statement in `OR` conditions.. +// See WhereBuilder.WhereOrGTE. func (m *Model) WhereOrGTE(column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrGTE(column, value)) } // WhereOrBetween builds `column BETWEEN min AND max` statement in `OR` conditions. +// See WhereBuilder.WhereOrBetween. func (m *Model) WhereOrBetween(column string, min, max interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrBetween(column, min, max)) } // WhereOrLike builds `column LIKE like` statement in `OR` conditions. +// See WhereBuilder.WhereOrLike. func (m *Model) WhereOrLike(column string, like interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrLike(column, like)) } // WhereOrIn builds `column IN (in)` statement in `OR` conditions. +// See WhereBuilder.WhereOrIn. func (m *Model) WhereOrIn(column string, in interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrIn(column, in)) } // WhereOrNull builds `columns[0] IS NULL OR columns[1] IS NULL ...` statement in `OR` conditions. +// See WhereBuilder.WhereOrNull. func (m *Model) WhereOrNull(columns ...string) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrNull(columns...)) } // WhereOrNotBetween builds `column NOT BETWEEN min AND max` statement in `OR` conditions. +// See WhereBuilder.WhereOrNotBetween. func (m *Model) WhereOrNotBetween(column string, min, max interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrNotBetween(column, min, max)) } // WhereOrNotLike builds `column NOT LIKE like` statement in `OR` conditions. +// See WhereBuilder.WhereOrNotLike. func (m *Model) WhereOrNotLike(column string, like interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrNotLike(column, like)) } // WhereOrNotIn builds `column NOT IN (in)` statement. +// See WhereBuilder.WhereOrNotIn. func (m *Model) WhereOrNotIn(column string, in interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrNotIn(column, in)) } // WhereOrNotNull builds `columns[0] IS NOT NULL OR columns[1] IS NOT NULL ...` statement in `OR` conditions. +// See WhereBuilder.WhereOrNotNull. func (m *Model) WhereOrNotNull(columns ...string) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrNotNull(columns...)) } diff --git a/database/gdb/gdb_model_whereor_prefix.go b/database/gdb/gdb_model_whereor_prefix.go index ebf5ad575ee..e336ed57c3f 100644 --- a/database/gdb/gdb_model_whereor_prefix.go +++ b/database/gdb/gdb_model_whereor_prefix.go @@ -7,66 +7,79 @@ package gdb // WhereOrPrefix performs as WhereOr, but it adds prefix to each field in where statement. +// See WhereBuilder.WhereOrPrefix. func (m *Model) WhereOrPrefix(prefix string, where interface{}, args ...interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefix(prefix, where, args...)) } // WhereOrPrefixLT builds `prefix.column < value` statement in `OR` conditions.. +// See WhereBuilder.WhereOrPrefixLT. func (m *Model) WhereOrPrefixLT(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixLT(prefix, column, value)) } // WhereOrPrefixLTE builds `prefix.column <= value` statement in `OR` conditions.. +// See WhereBuilder.WhereOrPrefixLTE. func (m *Model) WhereOrPrefixLTE(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixLTE(prefix, column, value)) } // WhereOrPrefixGT builds `prefix.column > value` statement in `OR` conditions.. +// See WhereBuilder.WhereOrPrefixGT. func (m *Model) WhereOrPrefixGT(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixGT(prefix, column, value)) } // WhereOrPrefixGTE builds `prefix.column >= value` statement in `OR` conditions.. +// See WhereBuilder.WhereOrPrefixGTE. func (m *Model) WhereOrPrefixGTE(prefix string, column string, value interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixGTE(prefix, column, value)) } // WhereOrPrefixBetween builds `prefix.column BETWEEN min AND max` statement in `OR` conditions. +// See WhereBuilder.WhereOrPrefixBetween. func (m *Model) WhereOrPrefixBetween(prefix string, column string, min, max interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixBetween(prefix, column, min, max)) } // WhereOrPrefixLike builds `prefix.column LIKE like` statement in `OR` conditions. +// See WhereBuilder.WhereOrPrefixLike. func (m *Model) WhereOrPrefixLike(prefix string, column string, like interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixLike(prefix, column, like)) } // WhereOrPrefixIn builds `prefix.column IN (in)` statement in `OR` conditions. +// See WhereBuilder.WhereOrPrefixIn. func (m *Model) WhereOrPrefixIn(prefix string, column string, in interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixIn(prefix, column, in)) } // WhereOrPrefixNull builds `prefix.columns[0] IS NULL OR prefix.columns[1] IS NULL ...` statement in `OR` conditions. +// See WhereBuilder.WhereOrPrefixNull. func (m *Model) WhereOrPrefixNull(prefix string, columns ...string) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNull(prefix, columns...)) } // WhereOrPrefixNotBetween builds `prefix.column NOT BETWEEN min AND max` statement in `OR` conditions. +// See WhereBuilder.WhereOrPrefixNotBetween. func (m *Model) WhereOrPrefixNotBetween(prefix string, column string, min, max interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNotBetween(prefix, column, min, max)) } // WhereOrPrefixNotLike builds `prefix.column NOT LIKE like` statement in `OR` conditions. +// See WhereBuilder.WhereOrPrefixNotLike. func (m *Model) WhereOrPrefixNotLike(prefix string, column string, like interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNotLike(prefix, column, like)) } // WhereOrPrefixNotIn builds `prefix.column NOT IN (in)` statement. +// See WhereBuilder.WhereOrPrefixNotIn. func (m *Model) WhereOrPrefixNotIn(prefix string, column string, in interface{}) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNotIn(prefix, column, in)) } // WhereOrPrefixNotNull builds `prefix.columns[0] IS NOT NULL OR prefix.columns[1] IS NOT NULL ...` statement in `OR` conditions. +// See WhereBuilder.WhereOrPrefixNotNull. func (m *Model) WhereOrPrefixNotNull(prefix string, columns ...string) *Model { return m.callWhereBuilder(m.whereBuilder.WhereOrPrefixNotNull(prefix, columns...)) } diff --git a/database/gdb/gdb_z_mysql_feature_model_builder_test.go b/database/gdb/gdb_z_mysql_feature_model_builder_test.go index 43e319731de..c38fabe6180 100644 --- a/database/gdb/gdb_z_mysql_feature_model_builder_test.go +++ b/database/gdb/gdb_z_mysql_feature_model_builder_test.go @@ -28,6 +28,7 @@ func Test_Model_Builder(t *testing.T) { t.Assert(len(all), 6) }) + // Where And gtest.C(t, func(t *gtest.T) { m := db.Model(table) b := m.Builder() @@ -43,4 +44,20 @@ func Test_Model_Builder(t *testing.T) { t.Assert(len(all), 1) }) + db.SetDebug(true) + // Where Or + gtest.C(t, func(t *gtest.T) { + m := db.Model(table) + b := m.Builder() + + all, err := m.WhereOr( + b.Where("id", g.Slice{1, 2, 3}).WhereOr("id", g.Slice{4, 5, 6}), + ).WhereOr( + b.Where("id", g.Slice{2, 3}).WhereOr("id", g.Slice{5, 6}), + ).WhereOr( + b.Where("id", g.Slice{3}).Where("id", g.Slice{1, 2, 3}), + ).All() + t.AssertNil(err) + t.Assert(len(all), 6) + }) } From d6471073178e379c278d0239f854f4fa3860a8db Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 7 May 2022 16:38:17 +0800 Subject: [PATCH 19/70] remove Sharding feature --- contrib/drivers/mssql/mssql.go | 2 +- contrib/drivers/oracle/oracle.go | 2 +- contrib/drivers/pgsql/pgsql.go | 2 +- database/gdb/gdb_core_underlying.go | 37 --- database/gdb/gdb_driver_mysql.go | 1 - database/gdb/gdb_model.go | 65 +++-- database/gdb/gdb_model_sharding.go | 245 ------------------ .../gdb/gdb_z_mysql_feature_sharding_test.go | 138 ---------- 8 files changed, 35 insertions(+), 457 deletions(-) delete mode 100644 database/gdb/gdb_model_sharding.go delete mode 100644 database/gdb/gdb_z_mysql_feature_sharding_test.go diff --git a/contrib/drivers/mssql/mssql.go b/contrib/drivers/mssql/mssql.go index c32c90a4fab..787a73d5a83 100644 --- a/contrib/drivers/mssql/mssql.go +++ b/contrib/drivers/mssql/mssql.go @@ -104,7 +104,7 @@ func (d *Driver) FilteredLink() string { // GetChars returns the security char for this type of database. func (d *Driver) GetChars() (charLeft string, charRight string) { - return "\"", "\"" + return `"`, `"` } // DoFilter deals with the sql string before commits it to underlying sql driver. diff --git a/contrib/drivers/oracle/oracle.go b/contrib/drivers/oracle/oracle.go index 3bab5bfc1ae..e6db605869c 100644 --- a/contrib/drivers/oracle/oracle.go +++ b/contrib/drivers/oracle/oracle.go @@ -108,7 +108,7 @@ func (d *Driver) FilteredLink() string { // GetChars returns the security char for this type of database. func (d *Driver) GetChars() (charLeft string, charRight string) { - return "\"", "\"" + return `"`, `"` } // DoFilter deals with the sql string before commits it to underlying sql driver. diff --git a/contrib/drivers/pgsql/pgsql.go b/contrib/drivers/pgsql/pgsql.go index e9d2ccfbee7..d474ecc73bd 100644 --- a/contrib/drivers/pgsql/pgsql.go +++ b/contrib/drivers/pgsql/pgsql.go @@ -106,7 +106,7 @@ func (d *Driver) FilteredLink() string { // GetChars returns the security char for this type of database. func (d *Driver) GetChars() (charLeft string, charRight string) { - return "\"", "\"" + return `"`, `"` } // DoFilter deals with the sql string before commits it to underlying sql driver. diff --git a/database/gdb/gdb_core_underlying.go b/database/gdb/gdb_core_underlying.go index 86857157ae2..a3c177cb61f 100644 --- a/database/gdb/gdb_core_underlying.go +++ b/database/gdb/gdb_core_underlying.go @@ -137,31 +137,6 @@ type sqlParsingHandlerOutput struct { DoCommitInput } -func (c *Core) sqlParsingHandler(ctx context.Context, in sqlParsingHandlerInput) (out *sqlParsingHandlerOutput, err error) { - var shardingOut *callShardingHandlerFromCtxOutput - // Sharding handling. - shardingOut, err = c.callShardingHandlerFromCtx(ctx, callShardingHandlerFromCtxInput{ - Sql: in.Sql, - FormattedSql: in.FormattedSql, - }) - if err != nil { - return - } - if shardingOut != nil { - if shardingOut.Sql != "" { - in.Sql = shardingOut.Sql - } - // If schema changes, it here creates and uses a new DB link operation object. - if shardingOut.Schema != c.db.GetSchema() { - in.Link, err = c.db.GetCore().GetLink(ctx, in.Link.IsOnMaster(), shardingOut.Schema) - } - } - out = &sqlParsingHandlerOutput{ - DoCommitInput: in.DoCommitInput, - } - return -} - // DoCommit commits current sql and arguments to underlying sql driver. func (c *Core) DoCommit(ctx context.Context, in DoCommitInput) (out DoCommitOutput, err error) { // Inject internal data into ctx, especially for transaction creating. @@ -180,18 +155,6 @@ func (c *Core) DoCommit(ctx context.Context, in DoCommitInput) (out DoCommitOutp timestampMilli1 = gtime.TimestampMilli() ) - // SQL parser handler. - sqlParsingHandlerOut, err := c.sqlParsingHandler(ctx, sqlParsingHandlerInput{ - DoCommitInput: in, - FormattedSql: formattedSql, - }) - if err != nil { - return - } - if sqlParsingHandlerOut != nil { - in = sqlParsingHandlerOut.DoCommitInput - } - // Trace span start. tr := otel.GetTracerProvider().Tracer(traceInstrumentName, trace.WithInstrumentationVersion(gf.VERSION)) ctx, span := tr.Start(ctx, in.Type, trace.WithSpanKind(trace.SpanKindInternal)) diff --git a/database/gdb/gdb_driver_mysql.go b/database/gdb/gdb_driver_mysql.go index cc9fcb2472a..ec84128ac76 100644 --- a/database/gdb/gdb_driver_mysql.go +++ b/database/gdb/gdb_driver_mysql.go @@ -13,7 +13,6 @@ import ( "net/url" _ "github.com/go-sql-driver/mysql" - "github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/internal/intlog" diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 98010a07004..148e09929b7 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -18,39 +18,38 @@ import ( // Model is core struct implementing the DAO for ORM. type Model struct { *modelWhereBuilder - db DB // Underlying DB interface. - tx *TX // Underlying TX interface. - rawSql string // rawSql is the raw SQL string which marks a raw SQL based Model not a table based Model. - schema string // Custom database schema. - linkType int // Mark for operation on master or slave. - tablesInit string // Table names when model initialization. - tables string // Operation table names, which can be more than one table names and aliases, like: "user", "user u", "user u, user_detail ud". - fields string // Operation fields, multiple fields joined using char ','. - fieldsEx string // Excluded operation fields, multiple fields joined using char ','. - withArray []interface{} // Arguments for With feature. - withAll bool // Enable model association operations on all objects that have "with" tag in the struct. - extraArgs []interface{} // Extra custom arguments for sql, which are prepended to the arguments before sql committed to underlying driver. - whereBuilder *WhereBuilder // Condition builder for where operation. - groupBy string // Used for "group by" statement. - orderBy string // Used for "order by" statement. - having []interface{} // Used for "having..." statement. - start int // Used for "select ... start, limit ..." statement. - limit int // Used for "select ... start, limit ..." statement. - option int // Option for extra operation features. - offset int // Offset statement for some databases grammar. - data interface{} // Data for operation, which can be type of map/[]map/struct/*struct/string, etc. - batch int // Batch number for batch Insert/Replace/Save operations. - filter bool // Filter data and where key-value pairs according to the fields of the table. - distinct string // Force the query to only return distinct results. - lockInfo string // Lock for update or in shared lock. - cacheEnabled bool // Enable sql result cache feature, which is mainly for indicating cache duration(especially 0) usage. - cacheOption CacheOption // Cache option for query statement. - hookHandler HookHandler // Hook functions for model hook feature. - shardingHandler ShardingHandler // Custom sharding handler for sharding feature. - unscoped bool // Disables soft deleting features when select/delete operations. - safe bool // If true, it clones and returns a new model object whenever operation done; or else it changes the attribute of current model. - onDuplicate interface{} // onDuplicate is used for ON "DUPLICATE KEY UPDATE" statement. - onDuplicateEx interface{} // onDuplicateEx is used for excluding some columns ON "DUPLICATE KEY UPDATE" statement. + db DB // Underlying DB interface. + tx *TX // Underlying TX interface. + rawSql string // rawSql is the raw SQL string which marks a raw SQL based Model not a table based Model. + schema string // Custom database schema. + linkType int // Mark for operation on master or slave. + tablesInit string // Table names when model initialization. + tables string // Operation table names, which can be more than one table names and aliases, like: "user", "user u", "user u, user_detail ud". + fields string // Operation fields, multiple fields joined using char ','. + fieldsEx string // Excluded operation fields, multiple fields joined using char ','. + withArray []interface{} // Arguments for With feature. + withAll bool // Enable model association operations on all objects that have "with" tag in the struct. + extraArgs []interface{} // Extra custom arguments for sql, which are prepended to the arguments before sql committed to underlying driver. + whereBuilder *WhereBuilder // Condition builder for where operation. + groupBy string // Used for "group by" statement. + orderBy string // Used for "order by" statement. + having []interface{} // Used for "having..." statement. + start int // Used for "select ... start, limit ..." statement. + limit int // Used for "select ... start, limit ..." statement. + option int // Option for extra operation features. + offset int // Offset statement for some databases grammar. + data interface{} // Data for operation, which can be type of map/[]map/struct/*struct/string, etc. + batch int // Batch number for batch Insert/Replace/Save operations. + filter bool // Filter data and where key-value pairs according to the fields of the table. + distinct string // Force the query to only return distinct results. + lockInfo string // Lock for update or in shared lock. + cacheEnabled bool // Enable sql result cache feature, which is mainly for indicating cache duration(especially 0) usage. + cacheOption CacheOption // Cache option for query statement. + hookHandler HookHandler // Hook functions for model hook feature. + unscoped bool // Disables soft deleting features when select/delete operations. + safe bool // If true, it clones and returns a new model object whenever operation done; or else it changes the attribute of current model. + onDuplicate interface{} // onDuplicate is used for ON "DUPLICATE KEY UPDATE" statement. + onDuplicateEx interface{} // onDuplicateEx is used for excluding some columns ON "DUPLICATE KEY UPDATE" statement. } type modelWhereBuilder = WhereBuilder diff --git a/database/gdb/gdb_model_sharding.go b/database/gdb/gdb_model_sharding.go deleted file mode 100644 index 4869f6f2053..00000000000 --- a/database/gdb/gdb_model_sharding.go +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gdb - -import ( - "context" - "strings" - - "github.com/gogf/gf/v2/container/gvar" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/os/gctx" - "github.com/longbridgeapp/sqlparser" -) - -// ShardingInput is input parameters for custom sharding handler. -type ShardingInput struct { - Table string // Current operation table name. - Schema string // Current operation schema, usually empty string which means uses default schema from configuration. - OperationData map[string]Value // Accurate readonly key-value data pairs from INSERT/UPDATE statement. - ConditionData map[string]Value // Accurate readonly key-value condition pairs from SELECT/UPDATE/DELETE statement. -} - -// ShardingOutput is output parameters for custom sharding handler. -type ShardingOutput struct { - Table string // New table name for current operation. Use empty string for no changes of table name. - Schema string // New schema name for current operation. Use empty string for using default schema from configuration. -} - -// ShardingHandler is a custom function for custom sharding table and schema for DB operation. -type ShardingHandler func(ctx context.Context, in ShardingInput) (out *ShardingOutput, err error) - -const ( - ctxKeyForShardingHandler gctx.StrKey = "ShardingHandler" -) - -// Sharding creates and returns a new model with sharding handler. -func (m *Model) Sharding(handler ShardingHandler) *Model { - var ( - ctx = m.GetCtx() - model = m.getModel() - ) - model.shardingHandler = handler - // Inject sharding handler into context. - model = model.Ctx(model.injectShardingInputCaller(ctx)) - return model -} - -// injectShardingInputCaller injects custom sharding handler into context. -func (m *Model) injectShardingInputCaller(ctx context.Context) context.Context { - if m.shardingHandler == nil { - return ctx - } - if ctx.Value(ctxKeyForShardingHandler) != nil { - return ctx - } - return context.WithValue(ctx, ctxKeyForShardingHandler, m.shardingHandler) -} - -type callShardingHandlerFromCtxInput struct { - Sql string - FormattedSql string -} - -type callShardingHandlerFromCtxOutput struct { - Sql string - Table string - Schema string - ParsedSqlOutput *parseFormattedSqlOutput -} - -func (c *Core) callShardingHandlerFromCtx( - ctx context.Context, in callShardingHandlerFromCtxInput, -) (out *callShardingHandlerFromCtxOutput, err error) { - var ( - newSql = in.Sql - ctxValue interface{} - shardingHandler ShardingHandler - ok bool - ) - // If no sharding handler, it does nothing. - if ctxValue = ctx.Value(ctxKeyForShardingHandler); ctxValue == nil { - return nil, nil - } - if shardingHandler, ok = ctxValue.(ShardingHandler); !ok { - return nil, nil - } - parsedOut, err := c.parseFormattedSql(in.FormattedSql) - if err != nil { - return nil, err - } - var shardingIn = ShardingInput{ - Table: parsedOut.Table, - Schema: c.db.GetSchema(), - OperationData: parsedOut.OperationData, - ConditionData: parsedOut.ConditionData, - } - shardingOut, err := shardingHandler(ctx, shardingIn) - if err != nil { - return nil, gerror.Wrap(err, `calling sharding handler failed`) - } - if shardingOut.Table != shardingIn.Table || shardingOut.Schema != shardingIn.Schema { - if shardingOut.Table != shardingIn.Table { - newSql, err = c.formatSqlWithNewTable(in.Sql, shardingOut.Table) - if err != nil { - return nil, err - } - } - out = &callShardingHandlerFromCtxOutput{ - Sql: newSql, - Table: shardingOut.Table, - Schema: shardingOut.Schema, - ParsedSqlOutput: parsedOut, - } - return out, nil - } - return nil, nil -} - -// formatSqlWithNewTable modifies given `sql` and returns a sql with new table name `table`. -func (c *Core) formatSqlWithNewTable(sql, table string) (newSql string, err error) { - parsedStmt, err := sqlparser.NewParser(strings.NewReader(sql)).ParseStatement() - if err != nil { - return "", gerror.Wrapf(err, `parse failed for SQL: %s`, sql) - } - newTable := &sqlparser.TableName{Name: &sqlparser.Ident{Name: table}} - switch stmt := parsedStmt.(type) { - case *sqlparser.SelectStatement: - stmt.FromItems = newTable - return stmt.String(), nil - case *sqlparser.InsertStatement: - stmt.TableName = newTable - return stmt.String(), nil - case *sqlparser.UpdateStatement: - stmt.TableName = newTable - return stmt.String(), nil - case *sqlparser.DeleteStatement: - stmt.TableName = newTable - return stmt.String(), nil - default: - return "", gerror.Wrapf(err, `unsupported SQL: %s`, sql) - } -} - -type parseFormattedSqlOutput struct { - Table string - OperationData map[string]Value - ConditionData map[string]Value - ParsedStmt sqlparser.Statement - SelectedFields []string -} - -func (c *Core) parseFormattedSql(formattedSql string) (*parseFormattedSqlOutput, error) { - var ( - condition sqlparser.Expr - err error - out = &parseFormattedSqlOutput{ - SelectedFields: make([]string, 0), - OperationData: make(map[string]Value), - ConditionData: make(map[string]Value), - } - ) - out.ParsedStmt, err = sqlparser.NewParser(strings.NewReader(formattedSql)).ParseStatement() - if err != nil { - return nil, gerror.Wrapf(err, `parse failed for SQL: %s`, formattedSql) - } - switch stmt := out.ParsedStmt.(type) { - case *sqlparser.SelectStatement: - if stmt.FromItems != nil { - table, ok := stmt.FromItems.(*sqlparser.TableName) - if !ok { - return nil, gerror.Newf( - `invalid table name "%s" in SQL: %s`, - stmt.FromItems.String(), formattedSql, - ) - } - out.Table = table.TableName() - } - condition = stmt.Condition - if stmt.Columns != nil { - for _, column := range *stmt.Columns { - if column.Alias != nil { - out.SelectedFields = append(out.SelectedFields, column.Alias.Name) - } else if column.Expr != nil { - out.SelectedFields = append(out.SelectedFields, column.Expr.String()) - } - } - } - - case *sqlparser.InsertStatement: - out.Table = stmt.TableName.TableName() - if len(stmt.Expressions) > 0 && len(stmt.ColumnNames) > 0 { - names := make([]string, len(stmt.ColumnNames)) - for i, ident := range stmt.ColumnNames { - names[i] = ident.Name - } - // It just uses the first item. - for i, expr := range stmt.Expressions[0].Exprs { - c.injectDataByExpr(out.OperationData, names[i], expr) - } - } - case *sqlparser.UpdateStatement: - out.Table = stmt.TableName.TableName() - condition = stmt.Condition - if len(stmt.Assignments) > 0 { - for _, assignment := range stmt.Assignments { - if len(assignment.Columns) > 0 { - c.injectDataByExpr(out.OperationData, assignment.Columns[0].Name, assignment.Expr) - } - } - } - case *sqlparser.DeleteStatement: - out.Table = stmt.TableName.TableName() - condition = stmt.Condition - - default: - return nil, gerror.Wrapf(err, `unsupported SQL: %s`, formattedSql) - } - - err = sqlparser.Walk(sqlparser.VisitFunc(func(node sqlparser.Node) error { - if n, ok := node.(*sqlparser.BinaryExpr); ok { - if x, ok := n.X.(*sqlparser.Ident); ok { - if n.Op == sqlparser.EQ { - c.injectDataByExpr(out.ConditionData, x.Name, n.Y) - } - } - } - return nil - }), condition) - return out, err -} - -func (c *Core) injectDataByExpr(data map[string]Value, name string, expr sqlparser.Expr) { - switch exprImp := expr.(type) { - case *sqlparser.StringLit: - data[name] = gvar.New(exprImp.Value) - case *sqlparser.NumberLit: - data[name] = gvar.New(exprImp.Value) - default: - data[name] = gvar.New(exprImp.String()) - } -} diff --git a/database/gdb/gdb_z_mysql_feature_sharding_test.go b/database/gdb/gdb_z_mysql_feature_sharding_test.go deleted file mode 100644 index aed2b18231d..00000000000 --- a/database/gdb/gdb_z_mysql_feature_sharding_test.go +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gdb_test - -import ( - "context" - "testing" - - "github.com/gogf/gf/v2/database/gdb" - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/test/gtest" -) - -func Test_Model_Sharding(t *testing.T) { - table1 := createTable() - table2 := createTable() - defer dropTable(table1) - defer dropTable(table2) - - gtest.C(t, func(t *gtest.T) { - _, err1 := db.Model(table1).Data(g.Map{ - "id": 1, - }).Insert() - t.AssertNil(err1) - _, err2 := db.Model(table2).Data(g.Map{ - "id": 2, - }).Insert() - t.AssertNil(err2) - }) - // no sharding. - gtest.C(t, func(t *gtest.T) { - all, err := db.Model(table1).All() - t.AssertNil(err) - t.Assert(len(all), 1) - t.Assert(all[0]["id"].String(), 1) - }) - // with sharding handler. - gtest.C(t, func(t *gtest.T) { - all, err := db.Model(table1).Sharding(func(ctx context.Context, in gdb.ShardingInput) (out *gdb.ShardingOutput, err error) { - out = &gdb.ShardingOutput{ - Table: table2, - } - return - }).All() - t.AssertNil(err) - t.Assert(len(all), 1) - t.Assert(all[0]["id"].String(), 2) - }) - // with sharding handler and no existence table name. - gtest.C(t, func(t *gtest.T) { - all, err := db.Model("none").Sharding(func(ctx context.Context, in gdb.ShardingInput) (out *gdb.ShardingOutput, err error) { - out = &gdb.ShardingOutput{ - Table: table2, - } - return - }).All() - t.AssertNil(err) - t.Assert(len(all), 1) - t.Assert(all[0]["id"].String(), 2) - }) - // with sharding handler and no existence table name and tables fields retrieving. - gtest.C(t, func(t *gtest.T) { - type User struct { - Id int - Passport string - Password string - NickName string - } - var users []User - err := db.Model("none").Sharding(func(ctx context.Context, in gdb.ShardingInput) (out *gdb.ShardingOutput, err error) { - out = &gdb.ShardingOutput{ - Table: table2, - } - return - }).Scan(&users) - t.AssertNil(err) - t.Assert(len(users), 1) - t.Assert(users[0].Id, 2) - }) -} - -func Test_Model_Sharding_Schema(t *testing.T) { - var ( - db1 = db - db2 = db.Schema(TestSchema2) - table1 = createTableWithDb(db1) - table2 = createTableWithDb(db2) - ) - - defer dropTableWithDb(db1, table1) - defer dropTableWithDb(db2, table2) - - gtest.C(t, func(t *gtest.T) { - _, err1 := db1.Model(table1).Data(g.Map{ - "id": 1, - }).Insert() - t.AssertNil(err1) - _, err2 := db2.Model(table2).Data(g.Map{ - "id": 2, - }).Insert() - t.AssertNil(err2) - }) - // no sharding. - gtest.C(t, func(t *gtest.T) { - all, err := db1.Model(table1).All() - t.AssertNil(err) - t.Assert(len(all), 1) - t.Assert(all[0]["id"].String(), 1) - }) - gtest.C(t, func(t *gtest.T) { - _, err := db1.Model(table2).All() - // Table not exist error. - t.AssertNE(err, nil) - }) - gtest.C(t, func(t *gtest.T) { - all, err := db2.Model(table2).All() - t.AssertNil(err) - t.Assert(len(all), 1) - t.Assert(all[0]["id"].String(), 2) - }) - // with sharding handler and no existence table name and schema change. - gtest.C(t, func(t *gtest.T) { - all, err := db1.Model("none").Sharding(func(ctx context.Context, in gdb.ShardingInput) (out *gdb.ShardingOutput, err error) { - out = &gdb.ShardingOutput{ - Table: table2, - Schema: TestSchema2, - } - return - }).All() - t.AssertNil(err) - t.Assert(len(all), 1) - t.Assert(all[0]["id"].String(), 2) - }) -} From b51cb53de6115be2cbeb2767d9e4c96b6d5bec90 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 09:35:57 +0800 Subject: [PATCH 20/70] merge --- .github/workflows/gf.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gf.yml b/.github/workflows/gf.yml index aafe11cdaef..4a9ee1170d5 100644 --- a/.github/workflows/gf.yml +++ b/.github/workflows/gf.yml @@ -6,13 +6,15 @@ on: branches: - master - develop - - feature/polaris + - feature/** + - fix/** + pull_request: branches: - master - develop - - feature/polaris - + - feature/** + - fix/** env: GF_DEBUG: 0 From 1eb7501361840ce4e0b90431f0545cfeb59bcdbd Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 7 May 2022 17:50:49 +0800 Subject: [PATCH 21/70] remove debug info for UT of package gdb --- database/gdb/gdb_z_mysql_feature_model_builder_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/database/gdb/gdb_z_mysql_feature_model_builder_test.go b/database/gdb/gdb_z_mysql_feature_model_builder_test.go index c38fabe6180..eb435f76eb5 100644 --- a/database/gdb/gdb_z_mysql_feature_model_builder_test.go +++ b/database/gdb/gdb_z_mysql_feature_model_builder_test.go @@ -44,7 +44,6 @@ func Test_Model_Builder(t *testing.T) { t.Assert(len(all), 1) }) - db.SetDebug(true) // Where Or gtest.C(t, func(t *gtest.T) { m := db.Model(table) From ea54d421826c2972631bef5b7d480983d83a2340 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 09:36:27 +0800 Subject: [PATCH 22/70] merge --- go.mod | 1 - go.sum | 4 ---- 2 files changed, 5 deletions(-) diff --git a/go.mod b/go.mod index cf7da42f7ef..af1073c39b1 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/go-sql-driver/mysql v1.6.0 github.com/gorilla/websocket v1.5.0 github.com/grokify/html-strip-tags-go v0.0.1 - github.com/longbridgeapp/sqlparser v0.3.1 github.com/olekukonko/tablewriter v0.0.5 go.opentelemetry.io/otel v1.0.0 go.opentelemetry.io/otel/sdk v1.0.0 diff --git a/go.sum b/go.sum index f99cb621ff4..a3b4c1ab1a0 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,6 @@ github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= -github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= github.com/golang/protobuf v1.2.0/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= @@ -48,8 +46,6 @@ github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/longbridgeapp/sqlparser v0.3.1 h1:iWOZWGIFgQrJRgobLXUNJdvqGRpbVXkyKUKUA5CNJBE= -github.com/longbridgeapp/sqlparser v0.3.1/go.mod h1:GIHaUq8zvYyHLCLMJJykx1CdM6LHtkUih/QaJXySSx4= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= From af893763ef6603b8e52c300af2bb0c170c7a8371 Mon Sep 17 00:00:00 2001 From: John Guo Date: Mon, 9 May 2022 14:22:28 +0800 Subject: [PATCH 23/70] improve hook feature for package gdb --- database/gdb/gdb_model.go | 3 --- database/gdb/gdb_model_delete.go | 8 ++++---- database/gdb/gdb_model_hook.go | 19 +++++++++++-------- database/gdb/gdb_model_insert.go | 4 ++-- database/gdb/gdb_model_select.go | 4 ++-- database/gdb/gdb_model_update.go | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 148e09929b7..287866d5bf3 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -17,7 +17,6 @@ import ( // Model is core struct implementing the DAO for ORM. type Model struct { - *modelWhereBuilder db DB // Underlying DB interface. tx *TX // Underlying TX interface. rawSql string // rawSql is the raw SQL string which marks a raw SQL based Model not a table based Model. @@ -52,8 +51,6 @@ type Model struct { onDuplicateEx interface{} // onDuplicateEx is used for excluding some columns ON "DUPLICATE KEY UPDATE" statement. } -type modelWhereBuilder = WhereBuilder - // ModelHandler is a function that handles given Model and returns a new Model that is custom modified. type ModelHandler func(m *Model) *Model diff --git a/database/gdb/gdb_model_delete.go b/database/gdb/gdb_model_delete.go index bab1d740b94..50e8f08dfd2 100644 --- a/database/gdb/gdb_model_delete.go +++ b/database/gdb/gdb_model_delete.go @@ -38,11 +38,11 @@ func (m *Model) Delete(where ...interface{}) (result sql.Result, err error) { in := &HookUpdateInput{ internalParamHookUpdate: internalParamHookUpdate{ internalParamHook: internalParamHook{ - link: m.getLink(true), - model: m, + link: m.getLink(true), }, handler: m.hookHandler.Update, }, + Model: m, Table: m.tables, Data: fmt.Sprintf(`%s=?`, m.db.GetCore().QuoteString(fieldNameDelete)), Condition: conditionWhere + conditionExtra, @@ -61,11 +61,11 @@ func (m *Model) Delete(where ...interface{}) (result sql.Result, err error) { in := &HookDeleteInput{ internalParamHookDelete: internalParamHookDelete{ internalParamHook: internalParamHook{ - link: m.getLink(true), - model: m, + link: m.getLink(true), }, handler: m.hookHandler.Delete, }, + Model: m, Table: m.tables, Condition: conditionStr, Args: conditionArgs, diff --git a/database/gdb/gdb_model_hook.go b/database/gdb/gdb_model_hook.go index fd823495d15..e1325c5449f 100644 --- a/database/gdb/gdb_model_hook.go +++ b/database/gdb/gdb_model_hook.go @@ -31,10 +31,9 @@ type HookHandler struct { // internalParamHook manages all internal parameters for hook operations. // The `internal` obviously means you cannot access these parameters outside this package. type internalParamHook struct { - link Link // Connection object from third party sql driver. - model *Model // Underlying Model object. - handlerCalled bool // Simple mark for custom handler called, in case of recursive calling. - removedWhere bool // Removed mark for condition string that was removed `WHERE` prefix. + link Link // Connection object from third party sql driver. + handlerCalled bool // Simple mark for custom handler called, in case of recursive calling. + removedWhere bool // Removed mark for condition string that was removed `WHERE` prefix. } type internalParamHookSelect struct { @@ -62,6 +61,7 @@ type internalParamHookDelete struct { // which is usually not be interesting for upper business hook handler. type HookSelectInput struct { internalParamHookSelect + Model *Model Table string Sql string Args []interface{} @@ -70,6 +70,7 @@ type HookSelectInput struct { // HookInsertInput holds the parameters for insert hook operation. type HookInsertInput struct { internalParamHookInsert + Model *Model Table string Data List Option DoInsertOption @@ -78,6 +79,7 @@ type HookInsertInput struct { // HookUpdateInput holds the parameters for update hook operation. type HookUpdateInput struct { internalParamHookUpdate + Model *Model Table string Data interface{} // Data can be type of: map[string]interface{}/string. You can use type assertion on `Data`. Condition string @@ -87,6 +89,7 @@ type HookUpdateInput struct { // HookDeleteInput holds the parameters for delete hook operation. type HookDeleteInput struct { internalParamHookDelete + Model *Model Table string Condition string Args []interface{} @@ -107,7 +110,7 @@ func (h *HookSelectInput) Next(ctx context.Context) (result Result, err error) { h.handlerCalled = true return h.handler(ctx, h) } - return h.model.db.DoSelect(ctx, h.link, h.Sql, h.Args...) + return h.Model.db.DoSelect(ctx, h.link, h.Sql, h.Args...) } // Next calls the next hook handler. @@ -116,7 +119,7 @@ func (h *HookInsertInput) Next(ctx context.Context) (result sql.Result, err erro h.handlerCalled = true return h.handler(ctx, h) } - return h.model.db.DoInsert(ctx, h.link, h.Table, h.Data, h.Option) + return h.Model.db.DoInsert(ctx, h.link, h.Table, h.Data, h.Option) } // Next calls the next hook handler. @@ -132,7 +135,7 @@ func (h *HookUpdateInput) Next(ctx context.Context) (result sql.Result, err erro if h.removedWhere { h.Condition = whereKeyInCondition + h.Condition } - return h.model.db.DoUpdate(ctx, h.link, h.Table, h.Data, h.Condition, h.Args...) + return h.Model.db.DoUpdate(ctx, h.link, h.Table, h.Data, h.Condition, h.Args...) } // Next calls the next hook handler. @@ -148,7 +151,7 @@ func (h *HookDeleteInput) Next(ctx context.Context) (result sql.Result, err erro if h.removedWhere { h.Condition = whereKeyInCondition + h.Condition } - return h.model.db.DoDelete(ctx, h.link, h.Table, h.Condition, h.Args...) + return h.Model.db.DoDelete(ctx, h.link, h.Table, h.Condition, h.Args...) } // Hook sets the hook functions for current model. diff --git a/database/gdb/gdb_model_insert.go b/database/gdb/gdb_model_insert.go index cc8cc4b10cd..2a6a460ee01 100644 --- a/database/gdb/gdb_model_insert.go +++ b/database/gdb/gdb_model_insert.go @@ -323,11 +323,11 @@ func (m *Model) doInsertWithOption(ctx context.Context, insertOption int) (resul in := &HookInsertInput{ internalParamHookInsert: internalParamHookInsert{ internalParamHook: internalParamHook{ - link: m.getLink(true), - model: m, + link: m.getLink(true), }, handler: m.hookHandler.Insert, }, + Model: m, Table: m.tables, Data: list, Option: doInsertOption, diff --git a/database/gdb/gdb_model_select.go b/database/gdb/gdb_model_select.go index d39fc4728ab..721924389b2 100644 --- a/database/gdb/gdb_model_select.go +++ b/database/gdb/gdb_model_select.go @@ -535,11 +535,11 @@ func (m *Model) doGetAllBySql(ctx context.Context, queryType int, sql string, ar in := &HookSelectInput{ internalParamHookSelect: internalParamHookSelect{ internalParamHook: internalParamHook{ - link: m.getLink(false), - model: m, + link: m.getLink(false), }, handler: m.hookHandler.Select, }, + Model: m, Table: m.tables, Sql: sql, Args: m.mergeArguments(args), diff --git a/database/gdb/gdb_model_update.go b/database/gdb/gdb_model_update.go index ab25e7c6da1..1a94d81ce66 100644 --- a/database/gdb/gdb_model_update.go +++ b/database/gdb/gdb_model_update.go @@ -80,11 +80,11 @@ func (m *Model) Update(dataAndWhere ...interface{}) (result sql.Result, err erro in := &HookUpdateInput{ internalParamHookUpdate: internalParamHookUpdate{ internalParamHook: internalParamHook{ - link: m.getLink(true), - model: m, + link: m.getLink(true), }, handler: m.hookHandler.Update, }, + Model: m, Table: m.tables, Data: newData, Condition: conditionStr, From 489698d9ce9a126939cf81ac2de6d97b0724e1ea Mon Sep 17 00:00:00 2001 From: wumengye Date: Sun, 3 Apr 2022 16:00:19 +0800 Subject: [PATCH 24/70] fix timezone bug when persisting *gtime.Time to db #1714 --- database/gdb/gdb_func.go | 6 +++--- database/gdb/gdb_z_init_test.go | 1 + database/gdb/gdb_z_mysql_internal_test.go | 1 + database/gdb/gdb_z_mysql_model_test.go | 18 +++++++++--------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index 4682f7dabe8..f9034111fed 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -766,7 +766,7 @@ func handleArguments(sql string, args []interface{}) (newSql string, newArgs []i // Special struct handling. case reflect.Struct: - switch v := arg.(type) { + switch arg.(type) { // The underlying driver supports time.Time/*time.Time types. case time.Time, *time.Time: newArgs = append(newArgs, arg) @@ -779,11 +779,11 @@ func handleArguments(sql string, args []interface{}) (newSql string, newArgs []i // according to underlying driver. And the underlying driver also // converts the time.Time to string automatically as the following does. case gtime.Time: - newArgs = append(newArgs, v.String()) + newArgs = append(newArgs, arg.(gtime.Time).Time) continue case *gtime.Time: - newArgs = append(newArgs, v.String()) + newArgs = append(newArgs, arg.(*gtime.Time).Time) continue default: diff --git a/database/gdb/gdb_z_init_test.go b/database/gdb/gdb_z_init_test.go index a7541c8a3e1..e4f8ba832fc 100644 --- a/database/gdb/gdb_z_init_test.go +++ b/database/gdb/gdb_z_init_test.go @@ -48,6 +48,7 @@ func init() { Port: "3306", User: TestDbUser, Pass: TestDbPass, + Timezone: "Asia/Shanghai", Name: parser.GetOpt("name", "").String(), Type: parser.GetOpt("type", "mysql").String(), Role: "master", diff --git a/database/gdb/gdb_z_mysql_internal_test.go b/database/gdb/gdb_z_mysql_internal_test.go index 4bbedc16c07..9909f2a82e0 100644 --- a/database/gdb/gdb_z_mysql_internal_test.go +++ b/database/gdb/gdb_z_mysql_internal_test.go @@ -40,6 +40,7 @@ func init() { Port: "3306", User: TestDbUser, Pass: TestDbPass, + Timezone: "Asia/Shanghai", Name: parser.GetOpt("name", "").String(), Type: parser.GetOpt("type", "mysql").String(), Role: "master", diff --git a/database/gdb/gdb_z_mysql_model_test.go b/database/gdb/gdb_z_mysql_model_test.go index 1744a5a8d5a..94259294e8e 100644 --- a/database/gdb/gdb_z_mysql_model_test.go +++ b/database/gdb/gdb_z_mysql_model_test.go @@ -3021,8 +3021,8 @@ func Test_Model_Issue1002(t *testing.T) { }) // where + time.Time arguments, UTC. gtest.C(t, func(t *gtest.T) { - t1, _ := time.Parse("2006-01-02 15:04:05", "2020-10-27 19:03:32") - t2, _ := time.Parse("2006-01-02 15:04:05", "2020-10-27 19:03:34") + t1, _ := time.Parse("2006-01-02 15:04:05", "2020-10-27 11:03:32") + t2, _ := time.Parse("2006-01-02 15:04:05", "2020-10-27 11:03:34") { v, err := db.Model(table).Fields("id").Where("create_time>? and create_time Date: Mon, 9 May 2022 20:42:41 +0800 Subject: [PATCH 25/70] fix issue #1714, #1727 --- database/gdb/gdb_func.go | 6 ------ database/gdb/gdb_z_init_test.go | 2 +- database/gdb/gdb_z_mysql_internal_test.go | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index f9034111fed..d652ad60c71 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -772,12 +772,6 @@ func handleArguments(sql string, args []interface{}) (newSql string, newArgs []i newArgs = append(newArgs, arg) continue - // Special handling for gtime.Time/*gtime.Time. - // - // DO NOT use its underlying gtime.Time.Time as its argument, - // because the std time.Time will be converted to certain timezone - // according to underlying driver. And the underlying driver also - // converts the time.Time to string automatically as the following does. case gtime.Time: newArgs = append(newArgs, arg.(gtime.Time).Time) continue diff --git a/database/gdb/gdb_z_init_test.go b/database/gdb/gdb_z_init_test.go index e4f8ba832fc..7a0e2e86596 100644 --- a/database/gdb/gdb_z_init_test.go +++ b/database/gdb/gdb_z_init_test.go @@ -48,7 +48,7 @@ func init() { Port: "3306", User: TestDbUser, Pass: TestDbPass, - Timezone: "Asia/Shanghai", + Timezone: "Asia/Shanghai", // For calculating UT cases of datetime zones in convenience. Name: parser.GetOpt("name", "").String(), Type: parser.GetOpt("type", "mysql").String(), Role: "master", diff --git a/database/gdb/gdb_z_mysql_internal_test.go b/database/gdb/gdb_z_mysql_internal_test.go index 9909f2a82e0..f2ee66f434b 100644 --- a/database/gdb/gdb_z_mysql_internal_test.go +++ b/database/gdb/gdb_z_mysql_internal_test.go @@ -40,7 +40,7 @@ func init() { Port: "3306", User: TestDbUser, Pass: TestDbPass, - Timezone: "Asia/Shanghai", + Timezone: "Asia/Shanghai", // For calculating UT cases of datetime zones in convenience. Name: parser.GetOpt("name", "").String(), Type: parser.GetOpt("type", "mysql").String(), Role: "master", From e6a9515d1e44d618707fb40dfa8891f71d5f788b Mon Sep 17 00:00:00 2001 From: John Guo Date: Mon, 9 May 2022 21:26:42 +0800 Subject: [PATCH 26/70] remove octal number converting for gconv.Int*/Uint* functions; fix issue #1733 --- database/gdb/gdb_z_mysql_model_test.go | 31 ++++++++++++++++++++++++++ util/gconv/gconv_int.go | 15 ++++--------- util/gconv/gconv_uint.go | 6 ----- util/gconv/gconv_z_unit_all_test.go | 4 ++-- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/database/gdb/gdb_z_mysql_model_test.go b/database/gdb/gdb_z_mysql_model_test.go index 94259294e8e..d03f0eec7ab 100644 --- a/database/gdb/gdb_z_mysql_model_test.go +++ b/database/gdb/gdb_z_mysql_model_test.go @@ -4286,3 +4286,34 @@ func Test_Model_Issue1701(t *testing.T) { t.Assert(value.String(), 100) }) } + +// https://github.com/gogf/gf/issues/1733 +func Test_Model_Issue1733(t *testing.T) { + table := "user_" + guid.S() + if _, err := db.Exec(ctx, fmt.Sprintf(` + CREATE TABLE %s ( + id int(8) unsigned zerofill NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + `, table, + )); err != nil { + gtest.AssertNil(err) + } + defer dropTable(table) + + gtest.C(t, func(t *gtest.T) { + for i := 1; i <= 10; i++ { + _, err := db.Model(table).Data(g.Map{ + "id": i, + }).Insert() + t.AssertNil(err) + } + + all, err := db.Model(table).OrderAsc("id").All() + t.AssertNil(err) + t.Assert(len(all), 10) + for i := 0; i < 10; i++ { + t.Assert(all[i]["id"].Int(), i+1) + } + }) +} diff --git a/util/gconv/gconv_int.go b/util/gconv/gconv_int.go index 63bd7752998..50626da7875 100644 --- a/util/gconv/gconv_int.go +++ b/util/gconv/gconv_int.go @@ -97,8 +97,10 @@ func Int64(any interface{}) int64 { if f, ok := value.(iInt64); ok { return f.Int64() } - s := String(value) - isMinus := false + var ( + s = String(value) + isMinus = false + ) if len(s) > 0 { if s[0] == '-' { isMinus = true @@ -116,15 +118,6 @@ func Int64(any interface{}) int64 { return v } } - // Octal - if len(s) > 1 && s[0] == '0' { - if v, e := strconv.ParseInt(s[1:], 8, 64); e == nil { - if isMinus { - return -v - } - return v - } - } // Decimal if v, e := strconv.ParseInt(s, 10, 64); e == nil { if isMinus { diff --git a/util/gconv/gconv_uint.go b/util/gconv/gconv_uint.go index 4f8d3b63a7e..fd0c258545e 100644 --- a/util/gconv/gconv_uint.go +++ b/util/gconv/gconv_uint.go @@ -104,12 +104,6 @@ func Uint64(any interface{}) uint64 { return v } } - // Octal - if len(s) > 1 && s[0] == '0' { - if v, e := strconv.ParseUint(s[1:], 8, 64); e == nil { - return v - } - } // Decimal if v, e := strconv.ParseUint(s, 10, 64); e == nil { return v diff --git a/util/gconv/gconv_z_unit_all_test.go b/util/gconv/gconv_z_unit_all_test.go index ab04223ccc2..87b0f430ff8 100644 --- a/util/gconv/gconv_z_unit_all_test.go +++ b/util/gconv/gconv_z_unit_all_test.go @@ -308,7 +308,7 @@ func Test_Int64_All(t *testing.T) { gtest.C(t, func(t *gtest.T) { var any interface{} = nil t.AssertEQ(gconv.Int64("0x00e"), int64(14)) - t.Assert(gconv.Int64("022"), int64(18)) + t.Assert(gconv.Int64("022"), int64(22)) t.Assert(gconv.Int64(any), int64(0)) t.Assert(gconv.Int64(true), 1) @@ -502,7 +502,7 @@ func Test_Uint64_All(t *testing.T) { gtest.C(t, func(t *gtest.T) { var any interface{} = nil t.AssertEQ(gconv.Uint64("0x00e"), uint64(14)) - t.Assert(gconv.Uint64("022"), uint64(18)) + t.Assert(gconv.Uint64("022"), uint64(22)) t.AssertEQ(gconv.Uint64(any), uint64(0)) t.AssertEQ(gconv.Uint64(true), uint64(1)) From 89acc92698b76cf02a6e0d9db2f94cd431b67620 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 09:37:52 +0800 Subject: [PATCH 27/70] merge --- contrib/registry/polaris/go.sum | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum index 903ca886bae..4addf8bc36e 100644 --- a/contrib/registry/polaris/go.sum +++ b/contrib/registry/polaris/go.sum @@ -48,8 +48,6 @@ github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= -github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= 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= @@ -105,8 +103,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN 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/longbridgeapp/sqlparser v0.3.1 h1:iWOZWGIFgQrJRgobLXUNJdvqGRpbVXkyKUKUA5CNJBE= -github.com/longbridgeapp/sqlparser v0.3.1/go.mod h1:GIHaUq8zvYyHLCLMJJykx1CdM6LHtkUih/QaJXySSx4= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= From c1f7a17d44daacde328236b72c2b677b119b9155 Mon Sep 17 00:00:00 2001 From: houseme Date: Sat, 7 May 2022 19:44:22 +0800 Subject: [PATCH 28/70] merge --- net/ghttp/ghttp_func.go | 1 - net/ghttp/ghttp_middleware_tracing.go | 6 ++---- net/ghttp/ghttp_request_middleware.go | 4 ++-- net/ghttp/ghttp_request_param.go | 6 ++---- net/ghttp/ghttp_request_param_request.go | 4 +--- net/ghttp/ghttp_response.go | 4 +--- net/ghttp/ghttp_server.go | 8 ++++---- net/ghttp/ghttp_server_admin_process.go | 12 +++--------- net/ghttp/ghttp_server_config.go | 2 +- net/ghttp/ghttp_server_graceful.go | 1 - net/ghttp/ghttp_server_handler.go | 1 - 11 files changed, 16 insertions(+), 33 deletions(-) diff --git a/net/ghttp/ghttp_func.go b/net/ghttp/ghttp_func.go index a261eb88e04..07c8fa8f1a2 100644 --- a/net/ghttp/ghttp_func.go +++ b/net/ghttp/ghttp_func.go @@ -49,7 +49,6 @@ func niceCallFunc(f func()) { gcode.CodeInternalError, 1, "exception recovered: %+v", exception, )) } - } } }() diff --git a/net/ghttp/ghttp_middleware_tracing.go b/net/ghttp/ghttp_middleware_tracing.go index 1a2bf2095e9..52f8dff61e9 100644 --- a/net/ghttp/ghttp_middleware_tracing.go +++ b/net/ghttp/ghttp_middleware_tracing.go @@ -40,9 +40,7 @@ const ( // internalMiddlewareServerTracing is a serer middleware that enables tracing feature using standards of OpenTelemetry. func internalMiddlewareServerTracing(r *Request) { - var ( - ctx = r.Context() - ) + ctx := r.Context() // Mark this request is handled by server tracing middleware, // to avoid repeated handling by the same middleware. if ctx.Value(tracingMiddlewareHandled) != nil { @@ -101,7 +99,7 @@ func internalMiddlewareServerTracing(r *Request) { span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, err)) } // Response content logging. - var resBodyContent = gstr.StrLimit(r.Response.BufferString(), gtrace.MaxContentLogSize(), "...") + resBodyContent := gstr.StrLimit(r.Response.BufferString(), gtrace.MaxContentLogSize(), "...") span.AddEvent(tracingEventHttpResponse, trace.WithAttributes( attribute.String(tracingEventHttpResponseHeaders, gconv.String(httputil.HeaderToMap(r.Response.Header()))), diff --git a/net/ghttp/ghttp_request_middleware.go b/net/ghttp/ghttp_request_middleware.go index 0b5cf8454ee..45de7b4e9cc 100644 --- a/net/ghttp/ghttp_request_middleware.go +++ b/net/ghttp/ghttp_request_middleware.go @@ -27,7 +27,7 @@ type middleware struct { // It's an important function controlling the workflow of the server request execution. func (m *middleware) Next() { var item *handlerParsedItem - var loop = true + loop := true for loop { // Check whether the request is excited. if m.request.IsExited() || m.handlerIndex >= len(m.request.handlers) { @@ -129,7 +129,7 @@ func (m *middleware) callHandlerFunc(funcInfo handlerFuncInfo) { if funcInfo.Func != nil { funcInfo.Func(m.request) } else { - var inputValues = []reflect.Value{ + inputValues := []reflect.Value{ reflect.ValueOf(m.request.Context()), } if funcInfo.Type.NumIn() == 2 { diff --git a/net/ghttp/ghttp_request_param.go b/net/ghttp/ghttp_request_param.go index 936dc4dc87b..f5887b9aa27 100644 --- a/net/ghttp/ghttp_request_param.go +++ b/net/ghttp/ghttp_request_param.go @@ -35,10 +35,8 @@ const ( parseTypeForm = 2 ) -var ( - // xmlHeaderBytes is the most common XML format header. - xmlHeaderBytes = []byte(" 0 && kvMap[0] != nil { filter = true } diff --git a/net/ghttp/ghttp_response.go b/net/ghttp/ghttp_response.go index e696a4f54fa..6ed50fae8b3 100644 --- a/net/ghttp/ghttp_response.go +++ b/net/ghttp/ghttp_response.go @@ -42,9 +42,7 @@ func newResponse(s *Server, w http.ResponseWriter) *Response { // ServeFile serves the file to the response. func (r *Response) ServeFile(path string, allowIndex ...bool) { - var ( - serveFile *staticFile - ) + var serveFile *staticFile if file := gres.Get(path); file != nil { serveFile = &staticFile{ File: file, diff --git a/net/ghttp/ghttp_server.go b/net/ghttp/ghttp_server.go index 3dd2500c77e..d43c53bf9d0 100644 --- a/net/ghttp/ghttp_server.go +++ b/net/ghttp/ghttp_server.go @@ -47,7 +47,7 @@ func init() { // serverProcessInit initializes some process configurations, which can only be done once. func serverProcessInit() { - var ctx = context.TODO() + ctx := context.TODO() if !serverProcessInitialized.Cas(false, true) { return } @@ -121,7 +121,7 @@ func GetServer(name ...interface{}) *Server { // Start starts listening on configured port. // This function does not block the process, you can use function Wait blocking the process. func (s *Server) Start() error { - var ctx = context.TODO() + ctx := context.TODO() // Swagger UI. if s.config.SwaggerPath != "" { @@ -414,7 +414,7 @@ func (s *Server) GetRoutes() []RouterItem { // Run starts server listening in blocking way. // It's commonly used for single server situation. func (s *Server) Run() { - var ctx = context.TODO() + ctx := context.TODO() if err := s.Start(); err != nil { s.Logger().Fatalf(ctx, `%+v`, err) @@ -437,7 +437,7 @@ func (s *Server) Run() { // Wait blocks to wait for all servers done. // It's commonly used in multiple server situation. func Wait() { - var ctx = context.TODO() + ctx := context.TODO() <-allDoneChan // Remove plugins. diff --git a/net/ghttp/ghttp_server_admin_process.go b/net/ghttp/ghttp_server_admin_process.go index fffe50ae83d..c4bb138d915 100644 --- a/net/ghttp/ghttp_server_admin_process.go +++ b/net/ghttp/ghttp_server_admin_process.go @@ -114,9 +114,7 @@ func checkActionFrequency() error { // forkReloadProcess creates a new child process and copies the fd to child process. func forkReloadProcess(ctx context.Context, newExeFilePath ...string) error { - var ( - path = os.Args[0] - ) + path := os.Args[0] if len(newExeFilePath) > 0 { path = newExeFilePath[0] } @@ -157,9 +155,7 @@ func forkReloadProcess(ctx context.Context, newExeFilePath ...string) error { // forkRestartProcess creates a new server process. func forkRestartProcess(ctx context.Context, newExeFilePath ...string) error { - var ( - path = os.Args[0] - ) + path := os.Args[0] if len(newExeFilePath) > 0 { path = newExeFilePath[0] } @@ -289,9 +285,7 @@ func forceCloseWebServers(ctx context.Context) { // handleProcessMessage receives and handles the message from processes, // which are commonly used for graceful reloading feature. func handleProcessMessage() { - var ( - ctx = context.TODO() - ) + ctx := context.TODO() for { if msg := gproc.Receive(adminGProcCommGroup); msg != nil { if bytes.EqualFold(msg.Data, []byte("exit")) { diff --git a/net/ghttp/ghttp_server_config.go b/net/ghttp/ghttp_server_config.go index 89eb8028808..1bac3e8166a 100644 --- a/net/ghttp/ghttp_server_config.go +++ b/net/ghttp/ghttp_server_config.go @@ -440,7 +440,7 @@ func (s *Server) SetListener(listeners ...net.Listener) error { // EnableHTTPS enables HTTPS with given certification and key files for the server. // The optional parameter `tlsConfig` specifies custom TLS configuration. func (s *Server) EnableHTTPS(certFile, keyFile string, tlsConfig ...*tls.Config) { - var ctx = context.TODO() + ctx := context.TODO() certFileRealPath := gfile.RealPath(certFile) if certFileRealPath == "" { certFileRealPath = gfile.RealPath(gfile.Pwd() + gfile.Separator + certFile) diff --git a/net/ghttp/ghttp_server_graceful.go b/net/ghttp/ghttp_server_graceful.go index 4f933e7b1b5..7d57cd53b9c 100644 --- a/net/ghttp/ghttp_server_graceful.go +++ b/net/ghttp/ghttp_server_graceful.go @@ -137,7 +137,6 @@ func (s *gracefulServer) ListenAndServeTLS(certFile, keyFile string, tlsConfig . } else { config.Certificates[0], err = tls.LoadX509KeyPair(certFile, keyFile) } - } if err != nil { return gerror.Wrapf(err, `open certFile "%s" and keyFile "%s" failed`, certFile, keyFile) diff --git a/net/ghttp/ghttp_server_handler.go b/net/ghttp/ghttp_server_handler.go index a35cd594182..18480949626 100644 --- a/net/ghttp/ghttp_server_handler.go +++ b/net/ghttp/ghttp_server_handler.go @@ -214,7 +214,6 @@ func (s *Server) searchStaticFile(uri string) *staticFile { IsDir: dir, } } - } } } From d7985f138d56684f2cc3a6db5ed43652e35b8f0f Mon Sep 17 00:00:00 2001 From: houseme Date: Sat, 7 May 2022 19:34:54 +0800 Subject: [PATCH 29/70] merge --- net/gsvc/gsvc.go | 4 +--- net/gsvc/gsvc_discovery.go | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index 3d26ad840ed..e1f99395885 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -99,9 +99,7 @@ const ( defaultTimeout = 5 * time.Second ) -var ( - defaultRegistry Registry -) +var defaultRegistry Registry // SetRegistry sets the default Registry implements as your own implemented interface. func SetRegistry(registry Registry) { diff --git a/net/gsvc/gsvc_discovery.go b/net/gsvc/gsvc_discovery.go index aba2f538aab..972fe801f9d 100644 --- a/net/gsvc/gsvc_discovery.go +++ b/net/gsvc/gsvc_discovery.go @@ -17,9 +17,7 @@ import ( "github.com/gogf/gf/v2/util/gutil" ) -var ( - watchedServiceMap = gmap.New(true) -) +var watchedServiceMap = gmap.New(true) type ServiceWatch func(service *Service) From 8fb3fc025f37033f1c85d24f0645dc7cd1c5717e Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 4 May 2022 18:54:31 +0800 Subject: [PATCH 30/70] feat:create polaris example --- contrib/registry/polaris/registry.go | 38 ++++++-- example/.gitignore | 100 +++++++++++++++++++++ example/go.mod | 7 +- example/go.sum | 105 +++++++++++++++++----- example/registry/polaris/client/main.go | 30 +++++++ example/registry/polaris/server/main.go | 24 +++++ example/trace/grpc_with_db/server/main.go | 3 +- net/gclient/gclient_config.go | 7 +- net/gclient/gclient_tracing.go | 4 +- net/gclient/gclient_tracing_tracer.go | 7 +- net/ghttp/ghttp_server_registry.go | 2 +- net/gsvc/gsvc.go | 29 +++--- net/gsvc/gsvc_discovery.go | 9 ++ net/gsvc/gsvc_metadata.go | 3 +- 14 files changed, 314 insertions(+), 54 deletions(-) create mode 100644 example/.gitignore create mode 100644 example/registry/polaris/client/main.go create mode 100644 example/registry/polaris/server/main.go diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index 943a29297c6..7db27c2f843 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -8,6 +8,7 @@ package polaris import ( "context" + "errors" "fmt" "net" "net/url" @@ -21,6 +22,7 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" ) @@ -47,13 +49,13 @@ type options struct { // service priority. Default value is 0. The smaller the value, the lower the priority Priority int - // To show service is healthy or not. Default value is True . + // To show service is healthy or not. Default value is True. Healthy bool // Heartbeat enable .Not in polaris . Default value is True. Heartbeat bool - // To show service is isolate or not. Default value is False . + // To show service is isolate or not. Default value is False. Isolate bool // TTL timeout. if node needs to use heartbeat to report,required. If not set,server will throw ErrorCode-400141 @@ -266,7 +268,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) // Deregister the registration. func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service) error { - split := strings.Split(serviceInstance.Key(), _instanceIDSeparator) + split := strings.Split(serviceInstance.ID, _instanceIDSeparator) for i, endpoint := range serviceInstance.Endpoints { // get url u, err := url.Parse(endpoint) @@ -307,8 +309,34 @@ func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service return nil } -// Registry returns the service instances in memory according to the service name. -func (r *Registry) Registry(_ context.Context, serviceName string) ([]*gsvc.Service, error) { +// Search returns the service instances in memory according to the service name. +func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { + var ( + u *url.URL + err error + serviceName string + ) + if len(in.Endpoints) > 0 { + u, err = url.Parse(in.Endpoints[0]) + if err != nil { + return nil, err + } + if u == nil { + return nil, errors.New("invalid endpoint") + } + serviceName = in.Name + u.Scheme + } else { + req := g.RequestFromCtx(ctx) + scheme := "http" + if req != nil { + proto := req.Header.Get("X-Forwarded-Proto") + if req.TLS != nil || gstr.Equal(proto, "https") { + scheme = "https" + } + } + serviceName = in.Name + scheme + } + // get all instances instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ GetAllInstancesRequest: model.GetAllInstancesRequest{ diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 00000000000..7a707e97e3b --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,100 @@ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Example user template template +### Example user template + +# IntelliJ project files +.idea +*.iml +out +gen +### Go template +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +*.log +*.json \ No newline at end of file diff --git a/example/go.mod b/example/go.mod index 0935aef276e..516858dee91 100644 --- a/example/go.mod +++ b/example/go.mod @@ -4,16 +4,19 @@ go 1.15 require ( github.com/gogf/gf/contrib/registry/etcd/v2 v2.0.0-rc2 + github.com/gogf/gf/contrib/registry/polaris/v2 v2.0.0-rc2 github.com/gogf/gf/contrib/trace/jaeger/v2 v2.0.0-rc2 - github.com/gogf/gf/v2 v2.0.0-rc2.0.20220128082344-48b5f3789470 + github.com/gogf/gf/v2 v2.0.0 github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.5.2 - google.golang.org/grpc v1.44.0 + github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b + google.golang.org/grpc v1.46.0 ) replace ( github.com/gogf/gf/contrib/registry/etcd/v2 => ../contrib/registry/etcd/ + github.com/gogf/gf/contrib/registry/polaris/v2 => ../contrib/registry/polaris/ github.com/gogf/gf/contrib/trace/jaeger/v2 => ../contrib/trace/jaeger/ github.com/gogf/gf/v2 => ../ ) diff --git a/example/go.sum b/example/go.sum index 0de41ebbbd8..6b6ced575dd 100644 --- a/example/go.sum +++ b/example/go.sum @@ -1,10 +1,12 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU= github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= +github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -22,6 +24,9 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E= github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -31,6 +36,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= @@ -49,13 +55,15 @@ 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/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= -github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= +github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -70,12 +78,13 @@ github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= -github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogf/katyusha v0.3.0/go.mod h1:AknlfKGS7HjZfLiz74Nd/eL2uq7bg+9aucZgfvXw8vQ= @@ -102,6 +111,13 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc= +github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg= +github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2/go.mod h1:pDgmNM6seYpwvPos3q+zxlXMsbve6mOIPucUnUOrI7Y= +github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks= +github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= +github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= +github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs= 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= @@ -112,20 +128,30 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= 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/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -150,12 +176,18 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 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/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= +github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -163,18 +195,24 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= -github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b h1:BFQejYBpde/ryb69+IDd8dsew7Y8z59mTFzDv8hMqX4= +github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= 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.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= @@ -196,7 +234,13 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L 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/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 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= @@ -209,7 +253,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 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.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM= go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E= @@ -231,18 +275,21 @@ go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqe go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec= go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= +go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= go.uber.org/zap v1.20.0 h1:N4oPlghZwYG55MlU6LXk/Zp00FVNE9X9wrYO8CEs4lc= go.uber.org/zap v1.20.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= 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-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-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 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= @@ -253,8 +300,9 @@ golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPI golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= 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= @@ -270,12 +318,14 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= +golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -297,6 +347,7 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -306,6 +357,7 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -315,11 +367,13 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw= +golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -328,12 +382,13 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= -golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= +golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 h1:dejsXyH3RsgJiGtZB8yNSjsPzZU/hAJ8aMJmRi7+Dtk= +golang.org/x/text v0.3.8-0.20220428233042-78819d01d041/go.mod h1:UqJy94PED2GK2o3pz2dHDKz1s05DEJMG9tubaZ3t0uI= 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-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= @@ -342,8 +397,8 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= -golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= +golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= 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= @@ -366,8 +421,10 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.44.0 h1:weqSxi/TMs1SqFRMHCtBgXRs8k3X39QIDEZ0pRcttUg= +google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8= +google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= 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= @@ -387,6 +444,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/example/registry/polaris/client/main.go b/example/registry/polaris/client/main.go new file mode 100644 index 00000000000..5c45087a2b4 --- /dev/null +++ b/example/registry/polaris/client/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "time" + + "github.com/polarismesh/polaris-go/pkg/config" + + "github.com/gogf/gf/contrib/registry/polaris/v2" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/os/gctx" +) + +func main() { + conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) + + gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100))) + + for i := 0; i < 100; i++ { + res, err := g.Client().Get(gctx.New(), `http://hello.svc/`) + if err != nil { + panic(err) + } + fmt.Println(res.ReadAllString()) + res.Close() + time.Sleep(time.Second) + } +} diff --git a/example/registry/polaris/server/main.go b/example/registry/polaris/server/main.go new file mode 100644 index 00000000000..a7ab6f33867 --- /dev/null +++ b/example/registry/polaris/server/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "github.com/polarismesh/polaris-go/pkg/config" + + "github.com/gogf/gf/contrib/registry/polaris/v2" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/net/gsvc" +) + +func main() { + conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) + + // TTL egt 2*time.Second + gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100))) + + s := g.Server(`hello.svc`) + s.BindHandler("/", func(r *ghttp.Request) { + g.Log().Info(r.Context(), `request received`) + r.Response.Write(`Hello world`) + }) + s.Run() +} diff --git a/example/trace/grpc_with_db/server/main.go b/example/trace/grpc_with_db/server/main.go index 2035785f417..78a986ae018 100644 --- a/example/trace/grpc_with_db/server/main.go +++ b/example/trace/grpc_with_db/server/main.go @@ -5,13 +5,14 @@ import ( "fmt" "time" + "github.com/gogf/katyusha/krpc" + "github.com/gogf/gf/contrib/trace/jaeger/v2" "github.com/gogf/gf/example/trace/grpc_with_db/protobuf/user" "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/os/gctx" - "github.com/gogf/katyusha/krpc" ) type server struct{} diff --git a/net/gclient/gclient_config.go b/net/gclient/gclient_config.go index 4ce29ef9488..01109562dfa 100644 --- a/net/gclient/gclient_config.go +++ b/net/gclient/gclient_config.go @@ -16,11 +16,12 @@ import ( "strings" "time" + "golang.org/x/net/proxy" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/internal/intlog" "github.com/gogf/gf/v2/text/gregex" "github.com/gogf/gf/v2/text/gstr" - "golang.org/x/net/proxy" ) // SetBrowserMode enables browser mode of the client. @@ -111,7 +112,7 @@ func (c *Client) SetRetry(retryCount int, retryInterval time.Duration) *Client { return c } -// SetRedirectLimit limit the number of jumps +// SetRedirectLimit limit the number of jumps. func (c *Client) SetRedirectLimit(redirectLimit int) *Client { c.CheckRedirect = func(req *http.Request, via []*http.Request) error { if len(via) >= redirectLimit { @@ -140,7 +141,7 @@ func (c *Client) SetProxy(proxyURL string) { v.Proxy = http.ProxyURL(_proxy) } } else { - var auth = &proxy.Auth{} + auth := &proxy.Auth{} user := _proxy.User.Username() if user != "" { auth.User = user diff --git a/net/gclient/gclient_tracing.go b/net/gclient/gclient_tracing.go index 86a2828c77c..b58f074b1e5 100644 --- a/net/gclient/gclient_tracing.go +++ b/net/gclient/gclient_tracing.go @@ -13,7 +13,6 @@ import ( "net/http" "net/http/httptrace" - "github.com/gogf/gf/v2/os/gctx" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" @@ -24,6 +23,7 @@ import ( "github.com/gogf/gf/v2/internal/httputil" "github.com/gogf/gf/v2/internal/utils" "github.com/gogf/gf/v2/net/gtrace" + "github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" ) @@ -48,7 +48,7 @@ const ( // internalMiddlewareTracing is a client middleware that enables tracing feature using standards of OpenTelemetry. func internalMiddlewareTracing(c *Client, r *http.Request) (response *Response, err error) { - var ctx = r.Context() + ctx := r.Context() // Mark this request is handled by server tracing middleware, // to avoid repeated handling by the same middleware. if ctx.Value(tracingMiddlewareHandled) != nil { diff --git a/net/gclient/gclient_tracing_tracer.go b/net/gclient/gclient_tracing_tracer.go index 4966f1fb721..9b92d7fd5fe 100644 --- a/net/gclient/gclient_tracing_tracer.go +++ b/net/gclient/gclient_tracing_tracer.go @@ -17,13 +17,14 @@ import ( "strings" "sync" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/trace" + "github.com/gogf/gf/v2/internal/utils" "github.com/gogf/gf/v2/net/gtrace" "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/trace" ) // clientTracer is used for implementing httptrace.ClientTrace. diff --git a/net/ghttp/ghttp_server_registry.go b/net/ghttp/ghttp_server_registry.go index 32b3e9cef69..8a6d5989a05 100644 --- a/net/ghttp/ghttp_server_registry.go +++ b/net/ghttp/ghttp_server_registry.go @@ -47,7 +47,7 @@ func (s *Server) doServiceRegister() { } s.service = &gsvc.Service{ Name: s.GetName(), - Endpoints: []string{fmt.Sprintf(`%s:%s`, ip, port)}, + Endpoints: []string{fmt.Sprintf(`%s://%s:%s`, protocol, ip, port)}, Metadata: metadata, } s.Logger().Debugf(ctx, `service register: %+v`, s.service) diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index e1f99395885..e7f1d557e06 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -64,22 +64,26 @@ type Metadata map[string]interface{} // SearchInput is the input for service searching. type SearchInput struct { - ID string // ID is the unique instance ID as registered. - Prefix string // Service prefix. - Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. - Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. - Name string // Name for the service. - Version string // Service version, eg: v1.0.0, v2.1.1, etc.} + ID string // ID is the unique instance ID as registered. + Prefix string // Service prefix. + Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. + Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. + Name string // Name for the service. + Version string // Service version, eg: v1.0.0, v2.1.1, etc.} + Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. + Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. } // WatchInput is the input for service watching. type WatchInput struct { - ID string // ID is the unique instance ID as registered. - Prefix string // Service prefix. - Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. - Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. - Name string // Name for the service. - Version string // Service version, eg: v1.0.0, v2.1.1, etc.} + ID string // ID is the unique instance ID as registered. + Prefix string // Service prefix. + Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. + Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. + Name string // Name for the service. + Version string // Service version, eg: v1.0.0, v2.1.1, etc.} + Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. + Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. } const ( @@ -112,6 +116,5 @@ func SetRegistry(registry Registry) { // GetRegistry returns the default Registry that is previously set. // It returns nil if no Registry is set. func GetRegistry() Registry { - return defaultRegistry } diff --git a/net/gsvc/gsvc_discovery.go b/net/gsvc/gsvc_discovery.go index 972fe801f9d..c8ebe448734 100644 --- a/net/gsvc/gsvc_discovery.go +++ b/net/gsvc/gsvc_discovery.go @@ -19,12 +19,15 @@ import ( var watchedServiceMap = gmap.New(true) +// ServiceWatch is used to watch the service status. type ServiceWatch func(service *Service) +// Get the watched service map. func Get(ctx context.Context, name string) (service *Service, err error) { return GetWithWatch(ctx, name, nil) } +// GetWithWatch is used to getting the service with watch. func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service *Service, err error) { v := watchedServiceMap.GetOrSetFuncLock(name, func() interface{} { var ( @@ -32,18 +35,22 @@ func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service services []*Service watcher Watcher ) + services, err = Search(ctx, SearchInput{ Prefix: s.Prefix, Deployment: s.Deployment, Namespace: s.Namespace, Name: s.Name, Version: s.Version, + Endpoints: s.Endpoints, + Metadata: s.Metadata, }) if err != nil { return nil } if len(services) == 0 { err = gerror.NewCodef(gcode.CodeNotFound, `service not found with name "%s"`, name) + return nil } service = services[0] @@ -53,6 +60,7 @@ func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service return nil } go watchAndUpdateService(watcher, service, watch) + return service }) if v != nil { @@ -72,6 +80,7 @@ func watchAndUpdateService(watcher Watcher, service *Service, watchFunc ServiceW services, err = watcher.Proceed() if err != nil { intlog.Errorf(ctx, `%+v`, err) + continue } if len(services) > 0 { diff --git a/net/gsvc/gsvc_metadata.go b/net/gsvc/gsvc_metadata.go index 015c4432a8d..6a0251f5895 100644 --- a/net/gsvc/gsvc_metadata.go +++ b/net/gsvc/gsvc_metadata.go @@ -15,10 +15,11 @@ func (m Metadata) Set(key string, value string) { m[key] = value } -// Get retrieves and returns value of specified key as gvar. +// Get retrieves and return value of specified key as gvar. func (m Metadata) Get(key string) *gvar.Var { if v, ok := m[key]; ok { return gvar.New(v) } + return nil } From 8f290f49bca94a49c66687cbfb4b1d05e4f5a823 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 4 May 2022 21:35:35 +0800 Subject: [PATCH 31/70] improve code --- contrib/registry/polaris/registry.go | 30 +--------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index 7db27c2f843..32888f1065e 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -8,7 +8,6 @@ package polaris import ( "context" - "errors" "fmt" "net" "net/url" @@ -22,7 +21,6 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/gsvc" - "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" ) @@ -311,36 +309,10 @@ func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service // Search returns the service instances in memory according to the service name. func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { - var ( - u *url.URL - err error - serviceName string - ) - if len(in.Endpoints) > 0 { - u, err = url.Parse(in.Endpoints[0]) - if err != nil { - return nil, err - } - if u == nil { - return nil, errors.New("invalid endpoint") - } - serviceName = in.Name + u.Scheme - } else { - req := g.RequestFromCtx(ctx) - scheme := "http" - if req != nil { - proto := req.Header.Get("X-Forwarded-Proto") - if req.TLS != nil || gstr.Equal(proto, "https") { - scheme = "https" - } - } - serviceName = in.Name + scheme - } - // get all instances instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ GetAllInstancesRequest: model.GetAllInstancesRequest{ - Service: serviceName, + Service: in.Name, Namespace: r.opt.Namespace, Timeout: &r.opt.Timeout, RetryCount: &r.opt.RetryCount, From a459f1520dce5347c9017c9fdcdf7929e46e3fd6 Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 5 May 2022 09:46:00 +0800 Subject: [PATCH 32/70] fix --- contrib/registry/polaris/go.mod | 2 +- contrib/registry/polaris/go.sum | 4 ++-- example/go.mod | 2 +- example/go.sum | 4 ++-- net/gsvc/gsvc_service.go | 16 ++++++++-------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/contrib/registry/polaris/go.mod b/contrib/registry/polaris/go.mod index a7e170d3f8f..7b76ec8725a 100644 --- a/contrib/registry/polaris/go.mod +++ b/contrib/registry/polaris/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/gogf/gf/v2 v2.0.0 - github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b + github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a ) replace github.com/gogf/gf/v2 => ../../../ diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum index 4addf8bc36e..ebd903abca9 100644 --- a/contrib/registry/polaris/go.sum +++ b/contrib/registry/polaris/go.sum @@ -137,8 +137,8 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b h1:BFQejYBpde/ryb69+IDd8dsew7Y8z59mTFzDv8hMqX4= -github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= +github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a h1:5Gjz26sK5NALVVobluxycmX7TMiBCnGaKQlZKS9ciaE= +github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= diff --git a/example/go.mod b/example/go.mod index 516858dee91..eb6db4db102 100644 --- a/example/go.mod +++ b/example/go.mod @@ -10,7 +10,7 @@ require ( github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.5.2 - github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b + github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a google.golang.org/grpc v1.46.0 ) diff --git a/example/go.sum b/example/go.sum index 6b6ced575dd..0cc3986075a 100644 --- a/example/go.sum +++ b/example/go.sum @@ -211,8 +211,8 @@ 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/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b h1:BFQejYBpde/ryb69+IDd8dsew7Y8z59mTFzDv8hMqX4= -github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220429065920-c8a803b6786b/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= +github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a h1:5Gjz26sK5NALVVobluxycmX7TMiBCnGaKQlZKS9ciaE= +github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= 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.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= diff --git a/net/gsvc/gsvc_service.go b/net/gsvc/gsvc_service.go index 64de6c4b05b..0c34624d525 100644 --- a/net/gsvc/gsvc_service.go +++ b/net/gsvc/gsvc_service.go @@ -22,13 +22,13 @@ const ( separator = "/" delimiter = "," - zero = iota - one - two - three - four - five - six + zero = 0 + one = 1 + two = 2 + three = 3 + four = 4 + five = 5 + six = 6 ) // NewServiceWithName creates and returns service from `name`. @@ -88,7 +88,7 @@ func (s *Service) KeyWithSchema() string { func (s *Service) KeyWithoutEndpoints() string { s.autoFillDefaultAttributes() - return "/" + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator) + return separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator) } // Value formats the service information and returns the Service as registering value. From 9190a21d36faca309727f8e93114b4eedd7ab5fe Mon Sep 17 00:00:00 2001 From: houseme Date: Sat, 7 May 2022 19:41:03 +0800 Subject: [PATCH 33/70] merge --- contrib/registry/etcd/etcd.go | 9 ++++++++- contrib/registry/etcd/etcd_registry.go | 6 ++++-- contrib/registry/polaris/registry.go | 10 ++++++---- net/gclient/gclient_discovery.go | 12 ++++++------ net/ghttp/ghttp_server_admin.go | 4 +--- net/ghttp/ghttp_server_cookie.go | 2 +- net/ghttp/ghttp_server_openapi.go | 4 +--- net/ghttp/ghttp_server_registry.go | 2 +- net/ghttp/ghttp_server_router.go | 14 ++++++-------- net/ghttp/ghttp_server_router_group.go | 4 +--- net/ghttp/ghttp_server_router_middleware.go | 8 ++------ net/ghttp/ghttp_server_router_serve.go | 6 +++--- net/ghttp/ghttp_server_service_handler.go | 6 +++--- net/ghttp/ghttp_server_service_object.go | 2 +- net/ghttp/ghttp_server_status.go | 2 +- net/gsvc/gsvc.go | 3 +++ net/gsvc/gsvc_discovery.go | 4 ++++ net/gsvc/gsvc_registry.go | 2 ++ net/gsvc/gsvc_search.go | 14 +++++++++----- net/gsvc/gsvc_service.go | 10 ++++++++-- 20 files changed, 71 insertions(+), 53 deletions(-) diff --git a/contrib/registry/etcd/etcd.go b/contrib/registry/etcd/etcd.go index a6fb9453d29..7439cf70ddb 100644 --- a/contrib/registry/etcd/etcd.go +++ b/contrib/registry/etcd/etcd.go @@ -10,19 +10,21 @@ package etcd import ( "time" + etcd3 "go.etcd.io/etcd/client/v3" + "github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/gsvc" "github.com/gogf/gf/v2/os/glog" "github.com/gogf/gf/v2/text/gstr" - etcd3 "go.etcd.io/etcd/client/v3" ) var ( _ gsvc.Registry = &Registry{} ) +// Registry implements gsvc.Registry interface. type Registry struct { client *etcd3.Client kv etcd3.KV @@ -31,15 +33,19 @@ type Registry struct { logger *glog.Logger } +// Option is the option for the etcd registry. type Option struct { Logger *glog.Logger KeepaliveTTL time.Duration } const ( + // DefaultKeepAliveTTL is the default keepalive TTL. DefaultKeepAliveTTL = 10 * time.Second + separator = "/" ) +// New creates and returns a new etcd registry. func New(address string, option ...Option) *Registry { endpoints := gstr.SplitAndTrim(address, ",") if len(endpoints) == 0 { @@ -54,6 +60,7 @@ func New(address string, option ...Option) *Registry { return NewWithClient(client, option...) } +// NewWithClient creates and returns a new etcd registry with the given client. func NewWithClient(client *etcd3.Client, option ...Option) *Registry { r := &Registry{ client: client, diff --git a/contrib/registry/etcd/etcd_registry.go b/contrib/registry/etcd/etcd_registry.go index 886f40ff2f4..fc7cb92cc34 100644 --- a/contrib/registry/etcd/etcd_registry.go +++ b/contrib/registry/etcd/etcd_registry.go @@ -9,9 +9,10 @@ package etcd import ( "context" + etcd3 "go.etcd.io/etcd/client/v3" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/net/gsvc" - etcd3 "go.etcd.io/etcd/client/v3" ) func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { @@ -42,6 +43,7 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { return err } go r.doKeepAlive(grant.ID, keepAliceCh) + service.Separator = separator return nil } @@ -64,7 +66,7 @@ func (r *Registry) doKeepAlive(leaseID etcd3.LeaseID, keepAliceCh <-chan *etcd3. case res, ok := <-keepAliceCh: if res != nil { - //r.logger.Debugf(ctx, `keepalive loop: %v, %s`, ok, res.String()) + // r.logger.Debugf(ctx, `keepalive loop: %v, %s`, ok, res.String()) } if !ok { r.logger.Noticef(ctx, `keepalive exit, lease id: %d`, leaseID) diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index 32888f1065e..0aba958731c 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -206,7 +206,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) service, err := r.provider.Register( &api.InstanceRegisterRequest{ InstanceRegisterRequest: model.InstanceRegisterRequest{ - Service: serviceInstance.Name + u.Scheme, + Service: serviceInstance.KeyWithoutEndpoints(), ServiceToken: r.opt.ServiceToken, Namespace: r.opt.Namespace, Host: host, @@ -239,7 +239,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) err = r.provider.Heartbeat(&api.InstanceHeartbeatRequest{ InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{ - Service: serviceInstance.Name + u.Scheme, + Service: serviceInstance.KeyWithoutEndpoints(), Namespace: r.opt.Namespace, Host: host, Port: portNum, @@ -261,6 +261,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) } // need to set InstanceID for Deregister serviceInstance.ID = strings.Join(ids, _instanceIDSeparator) + serviceInstance.Separator = _instanceIDSeparator return nil } @@ -289,7 +290,7 @@ func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service err = r.provider.Deregister( &api.InstanceDeRegisterRequest{ InstanceDeRegisterRequest: model.InstanceDeRegisterRequest{ - Service: serviceInstance.Name + u.Scheme, + Service: serviceInstance.KeyWithoutEndpoints(), ServiceToken: r.opt.ServiceToken, Namespace: r.opt.Namespace, InstanceID: split[i], @@ -312,7 +313,7 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Ser // get all instances instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ GetAllInstancesRequest: model.GetAllInstancesRequest{ - Service: in.Name, + Service: in.Key(), Namespace: r.opt.Namespace, Timeout: &r.opt.Timeout, RetryCount: &r.opt.RetryCount, @@ -441,5 +442,6 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { Version: metadata["version"], Metadata: gconv.Map(metadata), Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, instance.GetHost(), instance.GetPort())}, + Separator: _instanceIDSeparator, } } diff --git a/net/gclient/gclient_discovery.go b/net/gclient/gclient_discovery.go index 3d17443b9ad..5bded4afacc 100644 --- a/net/gclient/gclient_discovery.go +++ b/net/gclient/gclient_discovery.go @@ -34,13 +34,11 @@ func (n *discoveryNode) Address() string { return n.address } -var ( - clientSelectorMap = gmap.New(true) -) +var clientSelectorMap = gmap.New(true) // internalMiddlewareDiscovery is a client middleware that enables service discovery feature for client. func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response, err error) { - var ctx = r.Context() + ctx := r.Context() // Mark this request is handled by server tracing middleware, // to avoid repeated handling by the same middleware. if ctx.Value(discoveryMiddlewareHandled) != nil { @@ -54,7 +52,7 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response intlog.Printf(ctx, `http client watching service "%s" changed`, service.KeyWithoutEndpoints()) if v := clientSelectorMap.Get(service.KeyWithoutEndpoints()); v != nil { if err = updateSelectorNodesByService(v.(gsel.Selector), service); err != nil { - intlog.Errorf(context.Background(), `%+v`, err) + intlog.Errorf(context.Background(), `%+w`, err) } } }) @@ -65,9 +63,10 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response return c.Next(r) } // Balancer. - var selectorMapKey = service.KeyWithoutEndpoints() + selectorMapKey := service.KeyWithoutEndpoints() selector := clientSelectorMap.GetOrSetFuncLock(selectorMapKey, func() interface{} { intlog.Printf(ctx, `http client create selector for service "%s"`, selectorMapKey) + return gsel.GetBuilder().Build() }).(gsel.Selector) // Update selector nodes. @@ -77,6 +76,7 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response // Pick one node from multiple addresses. node, done, err := selector.Pick(ctx) if err != nil { + return nil, err } if done != nil { diff --git a/net/ghttp/ghttp_server_admin.go b/net/ghttp/ghttp_server_admin.go index e84d8d88639..3d2e29007fe 100644 --- a/net/ghttp/ghttp_server_admin.go +++ b/net/ghttp/ghttp_server_admin.go @@ -88,9 +88,7 @@ func (s *Server) EnableAdmin(pattern ...string) { // Shutdown shuts down current server. func (s *Server) Shutdown() error { - var ( - ctx = context.TODO() - ) + ctx := context.TODO() // Only shut down current servers. // It may have multiple underlying http servers. for _, v := range s.servers { diff --git a/net/ghttp/ghttp_server_cookie.go b/net/ghttp/ghttp_server_cookie.go index b5e618ba0ce..5164d9f464c 100644 --- a/net/ghttp/ghttp_server_cookie.go +++ b/net/ghttp/ghttp_server_cookie.go @@ -21,7 +21,7 @@ type Cookie struct { response *Response // Belonged HTTP response. } -// CookieOptions provides security config for cookies +// CookieOptions provides security config for cookies. type CookieOptions struct { SameSite http.SameSite // cookie SameSite property Secure bool // cookie Secure property diff --git a/net/ghttp/ghttp_server_openapi.go b/net/ghttp/ghttp_server_openapi.go index 035063f0434..f73d0b0d5d9 100644 --- a/net/ghttp/ghttp_server_openapi.go +++ b/net/ghttp/ghttp_server_openapi.go @@ -48,9 +48,7 @@ func (s *Server) initOpenApi() { // openapiSpec is a build-in handler automatic producing for openapi specification json file. func (s *Server) openapiSpec(r *Request) { - var ( - err error - ) + var err error if s.config.OpenApiPath == "" { r.Response.Write(`OpenApi specification file producing is disabled`) } else { diff --git a/net/ghttp/ghttp_server_registry.go b/net/ghttp/ghttp_server_registry.go index 8a6d5989a05..87cddf862ae 100644 --- a/net/ghttp/ghttp_server_registry.go +++ b/net/ghttp/ghttp_server_registry.go @@ -61,7 +61,7 @@ func (s *Server) doServiceDeregister() { if gsvc.GetRegistry() == nil { return } - var ctx = context.Background() + ctx := context.Background() s.Logger().Debugf(ctx, `service deregister: %+v`, s.service) if err := gsvc.Deregister(ctx, s.service); err != nil { s.Logger().Errorf(ctx, `%+v`, err) diff --git a/net/ghttp/ghttp_server_router.go b/net/ghttp/ghttp_server_router.go index 973ac35a854..41b230c739d 100644 --- a/net/ghttp/ghttp_server_router.go +++ b/net/ghttp/ghttp_server_router.go @@ -29,10 +29,8 @@ const ( stackFilterKey = "/net/ghttp/ghttp" ) -var ( - // handlerIdGenerator is handler item id generator. - handlerIdGenerator = gtype.NewInt() -) +// handlerIdGenerator is handler item id generator. +var handlerIdGenerator = gtype.NewInt() // routerMapKey creates and returns a unique router key for given parameters. // This key is used for Server.routerMap attribute, which is mainly for checks for @@ -99,7 +97,7 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { // Change the registered route according to meta info from its request structure. if handler.Info.Type != nil && handler.Info.Type.NumIn() == 2 { - var objectReq = reflect.New(handler.Info.Type.In(1)) + objectReq := reflect.New(handler.Info.Type.In(1)) if v := gmeta.Get(objectReq, goai.TagNamePath); !v.IsEmpty() { uri = v.String() } @@ -126,7 +124,7 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { } // Repeated router checks, this feature can be disabled by server configuration. - var routerKey = s.routerMapKey(handler.HookName, method, uri, domain) + routerKey := s.routerMapKey(handler.HookName, method, uri, domain) if !s.config.RouteOverWrite { switch handler.Type { case HandlerTypeHandler, HandlerTypeObject: @@ -184,7 +182,7 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { // priorities from high to low. // 3. There may be repeated router items in the router lists. The lists' priorities // from root to leaf are from low to high. - var p = s.serveTree[domain] + p := s.serveTree[domain] for i, part := range array { // Ignore empty URI part, like: /user//index if part == "" { @@ -389,7 +387,7 @@ func (s *Server) patternToRegular(rule string) (regular string, names []string) return rule, nil } regular = "^" - var array = strings.Split(rule[1:], "/") + array := strings.Split(rule[1:], "/") for _, v := range array { if len(v) == 0 { continue diff --git a/net/ghttp/ghttp_server_router_group.go b/net/ghttp/ghttp_server_router_group.go index 8d6b4de585a..65e3568bbeb 100644 --- a/net/ghttp/ghttp_server_router_group.go +++ b/net/ghttp/ghttp_server_router_group.go @@ -48,9 +48,7 @@ const ( groupBindTypeMiddleware = "MIDDLEWARE" ) -var ( - preBindItems = make([]*preBindItem, 0, 64) -) +var preBindItems = make([]*preBindItem, 0, 64) // handlePreBindItems is called when server starts, which does really route registering to the server. func (s *Server) handlePreBindItems(ctx context.Context) { diff --git a/net/ghttp/ghttp_server_router_middleware.go b/net/ghttp/ghttp_server_router_middleware.go index cf4adfc9deb..1b33ee8b53a 100644 --- a/net/ghttp/ghttp_server_router_middleware.go +++ b/net/ghttp/ghttp_server_router_middleware.go @@ -23,9 +23,7 @@ const ( // before or after service handler. The parameter `pattern` specifies what route pattern the middleware intercepts, // which is usually a "fuzzy" pattern like "/:name", "/*any" or "/{field}". func (s *Server) BindMiddleware(pattern string, handlers ...HandlerFunc) { - var ( - ctx = context.TODO() - ) + ctx := context.TODO() for _, handler := range handlers { s.setHandler(ctx, setHandlerInput{ Prefix: "", @@ -46,9 +44,7 @@ func (s *Server) BindMiddleware(pattern string, handlers ...HandlerFunc) { // Global middleware can be used standalone without service handler, which intercepts all dynamic requests // before or after service handler. func (s *Server) BindMiddlewareDefault(handlers ...HandlerFunc) { - var ( - ctx = context.TODO() - ) + ctx := context.TODO() for _, handler := range handlers { s.setHandler(ctx, setHandlerInput{ Prefix: "", diff --git a/net/ghttp/ghttp_server_router_serve.go b/net/ghttp/ghttp_server_router_serve.go index 0a2b214f132..05a01461672 100644 --- a/net/ghttp/ghttp_server_router_serve.go +++ b/net/ghttp/ghttp_server_router_serve.go @@ -56,7 +56,7 @@ func (s *Server) getHandlersWithCache(r *Request) (parsedItems []*handlerParsedI if xUrlPath := r.Header.Get(HeaderXUrlPath); xUrlPath != "" { path = xUrlPath } - var handlerCacheKey = s.serveHandlerKey(method, path, host) + handlerCacheKey := s.serveHandlerKey(method, path, host) value, err := s.serveCache.GetOrSetFunc(ctx, handlerCacheKey, func(ctx context.Context) (interface{}, error) { parsedItems, hasHook, hasServe = s.searchHandlers(method, path, host) if parsedItems != nil { @@ -82,7 +82,7 @@ func (s *Server) searchHandlers(method, path, domain string) (parsedItems []*han } // In case of double '/' URI, for example: // /user//index, //user/index, //user//index// - var previousIsSep = false + previousIsSep := false for i := 0; i < len(path); { if path[i] == '/' { if previousIsSep { @@ -212,7 +212,7 @@ func (s *Server) searchHandlers(method, path, domain string) (parsedItems []*han } } if parsedItemList.Len() > 0 { - var index = 0 + index := 0 parsedItems = make([]*handlerParsedItem, parsedItemList.Len()) for e := parsedItemList.Front(); e != nil; e = e.Next() { parsedItems[index] = e.Value.(*handlerParsedItem) diff --git a/net/ghttp/ghttp_server_service_handler.go b/net/ghttp/ghttp_server_service_handler.go index 25b4208f949..39767fb44e6 100644 --- a/net/ghttp/ghttp_server_service_handler.go +++ b/net/ghttp/ghttp_server_service_handler.go @@ -21,9 +21,9 @@ import ( // // Note that the parameter `handler` can be type of: // 1. func(*ghttp.Request) -// 2. func(context.Context, BizRequest)(BizResponse, error) +// 2. func(context.Context, BizRequest)(BizResponse, error). func (s *Server) BindHandler(pattern string, handler interface{}) { - var ctx = context.TODO() + ctx := context.TODO() funcInfo, err := s.checkAndCreateFuncInfo(handler, "", "", "") if err != nil { s.Logger().Fatalf(ctx, `%+v`, err) @@ -48,7 +48,7 @@ type doBindHandlerInput struct { // doBindHandler registers a handler function to server with given pattern. // // The parameter `pattern` is like: -// /user/list, put:/user, delete:/user, post:/user@goframe.org +// /user/list, put:/user, delete:/user, post:/user@goframe.org. func (s *Server) doBindHandler(ctx context.Context, in doBindHandlerInput) { s.setHandler(ctx, setHandlerInput{ Prefix: in.Prefix, diff --git a/net/ghttp/ghttp_server_service_object.go b/net/ghttp/ghttp_server_service_object.go index 8842841ab46..73d95f58453 100644 --- a/net/ghttp/ghttp_server_service_object.go +++ b/net/ghttp/ghttp_server_service_object.go @@ -22,7 +22,7 @@ import ( // The optional parameter `method` is used to specify the method to be registered, which // supports multiple method names; multiple methods are separated by char ',', case-sensitive. func (s *Server) BindObject(pattern string, object interface{}, method ...string) { - var bindMethod = "" + bindMethod := "" if len(method) > 0 { bindMethod = method[0] } diff --git a/net/ghttp/ghttp_server_status.go b/net/ghttp/ghttp_server_status.go index 3fbd146b4bc..783b4f6bb25 100644 --- a/net/ghttp/ghttp_server_status.go +++ b/net/ghttp/ghttp_server_status.go @@ -22,7 +22,7 @@ func (s *Server) getStatusHandler(status int, r *Request) []HandlerFunc { } // addStatusHandler sets the handler for given status code. -// The parameter `pattern` is like: domain#status +// The parameter `pattern` is like: domain#status. func (s *Server) addStatusHandler(pattern string, handler HandlerFunc) { if s.statusHandlerMap[pattern] == nil { s.statusHandlerMap[pattern] = make([]HandlerFunc, 0) diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index e7f1d557e06..c05cebf2b58 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -57,6 +57,7 @@ type Service struct { Version string // Service version, eg: v1.0.0, v2.1.1, etc. Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. + Separator string // Separator for service name and version, eg: _, -, etc. } // Metadata stores custom key-value pairs. @@ -72,6 +73,7 @@ type SearchInput struct { Version string // Service version, eg: v1.0.0, v2.1.1, etc.} Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. + Separator string // Separator for service name and version, eg: _, -, etc. } // WatchInput is the input for service watching. @@ -84,6 +86,7 @@ type WatchInput struct { Version string // Service version, eg: v1.0.0, v2.1.1, etc.} Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. + Separator string // Separator for service name and version, eg: _, -, etc. } const ( diff --git a/net/gsvc/gsvc_discovery.go b/net/gsvc/gsvc_discovery.go index c8ebe448734..3528e1e30f3 100644 --- a/net/gsvc/gsvc_discovery.go +++ b/net/gsvc/gsvc_discovery.go @@ -59,6 +59,7 @@ func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service if err != nil { return nil } + go watchAndUpdateService(watcher, service, watch) return service @@ -66,6 +67,7 @@ func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service if v != nil { service = v.(*Service) } + return } @@ -102,6 +104,7 @@ func Search(ctx context.Context, in SearchInput) ([]*Service, error) { return nil, gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) } ctx, _ = context.WithTimeout(ctx, defaultTimeout) + return defaultRegistry.Search(ctx, in) } @@ -110,5 +113,6 @@ func Watch(ctx context.Context, key string) (Watcher, error) { if defaultRegistry == nil { return nil, gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) } + return defaultRegistry.Watch(ctx, key) } diff --git a/net/gsvc/gsvc_registry.go b/net/gsvc/gsvc_registry.go index a73d5e9d684..24d0355d26e 100644 --- a/net/gsvc/gsvc_registry.go +++ b/net/gsvc/gsvc_registry.go @@ -20,6 +20,7 @@ func Register(ctx context.Context, service *Service) error { } ctx, cancel := context.WithTimeout(ctx, defaultTimeout) defer cancel() + return defaultRegistry.Register(ctx, service) } @@ -30,5 +31,6 @@ func Deregister(ctx context.Context, service *Service) error { } ctx, cancel := context.WithTimeout(ctx, defaultTimeout) defer cancel() + return defaultRegistry.Deregister(ctx, service) } diff --git a/net/gsvc/gsvc_search.go b/net/gsvc/gsvc_search.go index 4f9263b7f8f..9acf2ab0265 100644 --- a/net/gsvc/gsvc_search.go +++ b/net/gsvc/gsvc_search.go @@ -8,21 +8,25 @@ package gsvc // Key formats and returns a string for prefix searching purpose. func (s *SearchInput) Key() string { + if s.Separator == "" { + s.Separator = separator + } keyPrefix := "" if s.Prefix != "" { - keyPrefix += "/" + s.Prefix + keyPrefix += s.Separator + s.Prefix } if s.Deployment != "" { - keyPrefix += "/" + s.Deployment + keyPrefix += s.Separator + s.Deployment if s.Namespace != "" { - keyPrefix += "/" + s.Namespace + keyPrefix += s.Separator + s.Namespace if s.Name != "" { - keyPrefix += "/" + s.Name + keyPrefix += s.Separator + s.Name if s.Version != "" { - keyPrefix += "/" + s.Version + keyPrefix += s.Separator + s.Version } } } } + return keyPrefix } diff --git a/net/gsvc/gsvc_service.go b/net/gsvc/gsvc_service.go index 0c34624d525..813a1e7c7fe 100644 --- a/net/gsvc/gsvc_service.go +++ b/net/gsvc/gsvc_service.go @@ -73,8 +73,11 @@ func NewServiceWithKV(key, value []byte) (s *Service, err error) { // Key formats the service information and return the Service as registering key. func (s *Service) Key() string { + if s.Separator == "" { + s.Separator = separator + } serviceNameUnique := s.KeyWithoutEndpoints() - serviceNameUnique += separator + gstr.Join(s.Endpoints, ",") + serviceNameUnique += s.Separator + gstr.Join(s.Endpoints, ",") return serviceNameUnique } @@ -87,8 +90,11 @@ func (s *Service) KeyWithSchema() string { // KeyWithoutEndpoints formats the service information and returns a string as a unique name of service. func (s *Service) KeyWithoutEndpoints() string { s.autoFillDefaultAttributes() + if s.Separator == "" { + s.Separator = separator + } - return separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator) + return s.Separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) } // Value formats the service information and returns the Service as registering value. From 962a8bf1f1063679bad8c5cb99b30703f8ba783d Mon Sep 17 00:00:00 2001 From: houseme Date: Fri, 6 May 2022 12:09:10 +0800 Subject: [PATCH 34/70] fix --- contrib/registry/polaris/registry.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index 0aba958731c..c0cb61a8fd2 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -168,6 +168,7 @@ func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Regist // Register the registration. func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) error { ids := make([]string, 0, len(serviceInstance.Endpoints)) + serviceInstance.Separator = _instanceIDSeparator for _, endpoint := range serviceInstance.Endpoints { // get url u, err := url.Parse(endpoint) @@ -261,7 +262,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) } // need to set InstanceID for Deregister serviceInstance.ID = strings.Join(ids, _instanceIDSeparator) - serviceInstance.Separator = _instanceIDSeparator + return nil } From 29c3f3d311cd410bba7dd2a09057158cd7c2478d Mon Sep 17 00:00:00 2001 From: houseme Date: Sat, 7 May 2022 19:51:26 +0800 Subject: [PATCH 35/70] upgrade polaris-go version --- contrib/registry/polaris/go.mod | 2 +- contrib/registry/polaris/go.sum | 349 +++++++++++++++++++++++++++++++- 2 files changed, 344 insertions(+), 7 deletions(-) diff --git a/contrib/registry/polaris/go.mod b/contrib/registry/polaris/go.mod index 7b76ec8725a..6d16b18b538 100644 --- a/contrib/registry/polaris/go.mod +++ b/contrib/registry/polaris/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/gogf/gf/v2 v2.0.0 - github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a + github.com/polarismesh/polaris-go v1.1.0 ) replace github.com/gogf/gf/v2 => ../../../ diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum index ebd903abca9..bffe7ed1ce1 100644 --- a/contrib/registry/polaris/go.sum +++ b/contrib/registry/polaris/go.sum @@ -1,13 +1,54 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +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/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= @@ -43,16 +84,39 @@ github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwV github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +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-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 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= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= 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.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= 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= @@ -71,18 +135,36 @@ github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhS github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 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.4.1/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/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +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 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +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/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= @@ -94,10 +176,26 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +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/konsorten/go-windows-terminal-sequences v1.0.3/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= @@ -110,10 +208,18 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +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/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +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/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= @@ -133,14 +239,41 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a h1:5Gjz26sK5NALVVobluxycmX7TMiBCnGaKQlZKS9ciaE= -github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= +github.com/polarismesh/polaris-go v1.1.0 h1:nFvn3q3XaVFhzF7pBnIySrN0ZZBwvbbYXC5r2DpsQN0= +github.com/polarismesh/polaris-go v1.1.0/go.mod h1:tquawfjEKp1W3ffNJQSzhfditjjoZ7tvhOCElN7Efzs= +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.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= +github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +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/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= +github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= +github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= +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.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= +github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +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/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= @@ -148,13 +281,24 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9 github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +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/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= go.opentelemetry.io/otel/sdk v1.0.0 h1:BNPMYUONPNbLneMttKSjQhOTlFLOD9U22HNG1KrIN2Y= @@ -170,16 +314,43 @@ go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.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-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-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +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/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= 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-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= @@ -187,69 +358,167 @@ golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2 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= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/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-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +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-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/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-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= 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-20190227155943-e225da77a7e6/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-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/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-20180909124046-d0be0721c37e/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-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 h1:dejsXyH3RsgJiGtZB8yNSjsPzZU/hAJ8aMJmRi7+Dtk= golang.org/x/text v0.3.8-0.20220428233042-78819d01d041/go.mod h1:UqJy94PED2GK2o3pz2dHDKz1s05DEJMG9tubaZ3t0uI= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/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-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/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-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= @@ -259,17 +528,71 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T 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/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= 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/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 h1:PDIOdWxZ8eRizhKa1AAvY53xsvLB1cWorMjslvY3VA8= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 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.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A= @@ -282,21 +605,27 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi 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.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 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/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= @@ -305,4 +634,12 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/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/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= From a5200f868d51fd6f9f23f3f274701e7858301d33 Mon Sep 17 00:00:00 2001 From: houseme Date: Mon, 9 May 2022 22:09:38 +0800 Subject: [PATCH 36/70] upgrade polaris-go version --- contrib/registry/polaris/registry.go | 3 + example/go.mod | 2 +- example/go.sum | 261 ++++++++++++++++++++++++++- 3 files changed, 259 insertions(+), 7 deletions(-) diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index c0cb61a8fd2..51b29d903cc 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -168,6 +168,7 @@ func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Regist // Register the registration. func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) error { ids := make([]string, 0, len(serviceInstance.Endpoints)) + // set separator serviceInstance.Separator = _instanceIDSeparator for _, endpoint := range serviceInstance.Endpoints { // get url @@ -269,6 +270,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) // Deregister the registration. func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service) error { split := strings.Split(serviceInstance.ID, _instanceIDSeparator) + serviceInstance.Separator = _instanceIDSeparator for i, endpoint := range serviceInstance.Endpoints { // get url u, err := url.Parse(endpoint) @@ -311,6 +313,7 @@ func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service // Search returns the service instances in memory according to the service name. func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { + in.Separator = _instanceIDSeparator // get all instances instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ GetAllInstancesRequest: model.GetAllInstancesRequest{ diff --git a/example/go.mod b/example/go.mod index eb6db4db102..2e0a92f625f 100644 --- a/example/go.mod +++ b/example/go.mod @@ -10,7 +10,7 @@ require ( github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.5.2 - github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a + github.com/polarismesh/polaris-go v1.1.0 google.golang.org/grpc v1.46.0 ) diff --git a/example/go.sum b/example/go.sum index 0cc3986075a..6de80761e5b 100644 --- a/example/go.sum +++ b/example/go.sum @@ -1,9 +1,41 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= @@ -17,6 +49,7 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= 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/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= @@ -65,6 +98,9 @@ github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwV github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= @@ -84,8 +120,6 @@ github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfC github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= -github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogf/katyusha v0.3.0/go.mod h1:AknlfKGS7HjZfLiz74Nd/eL2uq7bg+9aucZgfvXw8vQ= github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 h1:s28bNu6QekQG3XFFB3G6YV3AGvQz8Uj4lBu/WXIeF28= @@ -95,11 +129,22 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a 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/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= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= 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.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= 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= @@ -118,20 +163,36 @@ github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhS github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 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.4.1/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/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 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 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +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/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= @@ -144,12 +205,18 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -164,8 +231,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN 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/longbridgeapp/sqlparser v0.3.1 h1:iWOZWGIFgQrJRgobLXUNJdvqGRpbVXkyKUKUA5CNJBE= -github.com/longbridgeapp/sqlparser v0.3.1/go.mod h1:GIHaUq8zvYyHLCLMJJykx1CdM6LHtkUih/QaJXySSx4= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= @@ -175,6 +240,7 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +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/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -211,26 +277,34 @@ 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/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a h1:5Gjz26sK5NALVVobluxycmX7TMiBCnGaKQlZKS9ciaE= -github.com/polarismesh/polaris-go v1.1.0-beta.0.0.20220504133205-fe477374370a/go.mod h1:pXNvQS2mL3HzyAj9PhKUjJsfAgbXFA1EBmBG7Yc2KdE= +github.com/polarismesh/polaris-go v1.1.0 h1:nFvn3q3XaVFhzF7pBnIySrN0ZZBwvbbYXC5r2DpsQN0= +github.com/polarismesh/polaris-go v1.1.0/go.mod h1:tquawfjEKp1W3ffNJQSzhfditjjoZ7tvhOCElN7Efzs= 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.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= +github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= 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/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= +github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= +github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= 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.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= +github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 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= @@ -250,7 +324,9 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= @@ -260,6 +336,11 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnT go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk= go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y= go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= @@ -287,17 +368,41 @@ go.uber.org/zap v1.20.0 h1:N4oPlghZwYG55MlU6LXk/Zp00FVNE9X9wrYO8CEs4lc= go.uber.org/zap v1.20.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= 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-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-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +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/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= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -311,16 +416,33 @@ golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73r 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-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 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-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/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-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -328,12 +450,18 @@ golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR3 golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= 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-20190227155943-e225da77a7e6/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-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -342,18 +470,37 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/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-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -376,7 +523,9 @@ golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0 golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -384,15 +533,51 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 h1:dejsXyH3RsgJiGtZB8yNSjsPzZU/hAJ8aMJmRi7+Dtk= golang.org/x/text v0.3.8-0.20220428233042-78819d01d041/go.mod h1:UqJy94PED2GK2o3pz2dHDKz1s05DEJMG9tubaZ3t0uI= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/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-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/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-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= @@ -404,19 +589,73 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T 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/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= 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/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 h1:YxHp5zqIcAShDEvRr5/0rVESVS+njYF68PSdazrNLJo= google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 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.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= @@ -433,6 +672,7 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi 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.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= @@ -443,6 +683,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= @@ -461,5 +702,13 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/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/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= From 7361d4fe4530a4b70486c0eef541a44dbf6f3247 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 16:15:05 +0800 Subject: [PATCH 37/70] fix --- contrib/registry/polaris/registry_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index 7b0f64e54b7..ad30d39c48f 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -132,7 +132,12 @@ func TestGetService(t *testing.T) { t.Fatal(err) } time.Sleep(time.Second * 1) - serviceInstances, err := r.Registry(ctx, "goframe-provider-4-tcp") + serviceInstances, err := r.Search(ctx, gsvc.SearchInput{ + Name: svc.Name, + Version: svc.Version, + Metadata: svc.Metadata, + Endpoints: svc.Endpoints, + }) if err != nil { t.Fatal(err) } From f56f0fd2e2cdf063d8fd517906c5795a838f1333 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 20:25:10 +0800 Subject: [PATCH 38/70] fix --- contrib/registry/polaris/registry_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index ad30d39c48f..4fa2c074eb0 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -31,7 +31,7 @@ func TestRegistry(t *testing.T) { ctx := context.Background() svc := &gsvc.Service{ - Name: "goframe-provider-0-", + Name: "goframe-provider-0-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, @@ -48,7 +48,7 @@ func TestRegistry(t *testing.T) { } } -// TestRegistryMany . TestRegistryManyService +// TestRegistryMany TestRegistryManyService func TestRegistryMany(t *testing.T) { conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) @@ -59,19 +59,19 @@ func TestRegistryMany(t *testing.T) { ) svc := &gsvc.Service{ - Name: "goframe-provider-1-", + Name: "goframe-provider-1-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, } svc1 := &gsvc.Service{ - Name: "goframe-provider-2-", + Name: "goframe-provider-2-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9001?isSecure=false"}, } svc2 := &gsvc.Service{ - Name: "goframe-provider-3-", + Name: "goframe-provider-3-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9002?isSecure=false"}, @@ -121,7 +121,7 @@ func TestGetService(t *testing.T) { ctx := context.Background() svc := &gsvc.Service{ - Name: "goframe-provider-4-", + Name: "goframe-provider-4-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, @@ -164,7 +164,7 @@ func TestWatch(t *testing.T) { ctx := gctx.New() svc := &gsvc.Service{ - Name: "goframe-provider-4-", + Name: "goframe-provider-4-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, From 8e41142822448dda0b4de57163742bb8c2e38aeb Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 20:49:11 +0800 Subject: [PATCH 39/70] test --- contrib/registry/polaris/registry_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index 4fa2c074eb0..b8827b81dda 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -170,7 +170,7 @@ func TestWatch(t *testing.T) { Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, } - watch, err := r.Watch(context.Background(), "goframe-provider-4-tcp") + watch, err := r.Watch(context.Background(), svc.Key()) if err != nil { t.Fatal(err) } From 2467c0e972aff0f920dc9b59a86840404adf25b5 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 22:55:56 +0800 Subject: [PATCH 40/70] fix --- contrib/registry/polaris/registry_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index b8827b81dda..14122a99ba3 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -170,7 +170,7 @@ func TestWatch(t *testing.T) { Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, } - watch, err := r.Watch(context.Background(), svc.Key()) + watch, err := r.Watch(context.Background(), svc.KeyWithoutEndpoints()) if err != nil { t.Fatal(err) } From bde610b1250752c7e8ecefa33b5af1a78c4ecc7c Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 23:36:00 +0800 Subject: [PATCH 41/70] test --- contrib/registry/polaris/registry_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index 14122a99ba3..55da28c9c8a 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -35,6 +35,7 @@ func TestRegistry(t *testing.T) { Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + Separator: _instanceIDSeparator, } err := r.Register(ctx, svc) @@ -63,18 +64,21 @@ func TestRegistryMany(t *testing.T) { Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + Separator: _instanceIDSeparator, } svc1 := &gsvc.Service{ Name: "goframe-provider-2-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9001?isSecure=false"}, + Separator: _instanceIDSeparator, } svc2 := &gsvc.Service{ Name: "goframe-provider-3-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9002?isSecure=false"}, + Separator: _instanceIDSeparator, } err := r.Register(context.Background(), svc) @@ -125,6 +129,7 @@ func TestGetService(t *testing.T) { Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + Separator: _instanceIDSeparator, } err := r.Register(ctx, svc) @@ -137,6 +142,7 @@ func TestGetService(t *testing.T) { Version: svc.Version, Metadata: svc.Metadata, Endpoints: svc.Endpoints, + Separator: _instanceIDSeparator, }) if err != nil { t.Fatal(err) @@ -168,6 +174,7 @@ func TestWatch(t *testing.T) { Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + Separator: _instanceIDSeparator, } watch, err := r.Watch(context.Background(), svc.KeyWithoutEndpoints()) From 8b4e0f3a635abef5b0e085d4fea400a1efb40e5b Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 11 May 2022 23:52:46 +0800 Subject: [PATCH 42/70] test --- net/gsvc/gsvc_service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/gsvc/gsvc_service.go b/net/gsvc/gsvc_service.go index 813a1e7c7fe..7fd1cd1107c 100644 --- a/net/gsvc/gsvc_service.go +++ b/net/gsvc/gsvc_service.go @@ -94,6 +94,10 @@ func (s *Service) KeyWithoutEndpoints() string { s.Separator = separator } + if s.Separator != separator { + return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) + } + return s.Separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) } From 37a93a5a6eaeda3cad66c9beba3d4e20c81740fd Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 00:02:10 +0800 Subject: [PATCH 43/70] test --- net/gsvc/gsvc_search.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/gsvc/gsvc_search.go b/net/gsvc/gsvc_search.go index 9acf2ab0265..a13f85513f1 100644 --- a/net/gsvc/gsvc_search.go +++ b/net/gsvc/gsvc_search.go @@ -13,7 +13,11 @@ func (s *SearchInput) Key() string { } keyPrefix := "" if s.Prefix != "" { - keyPrefix += s.Separator + s.Prefix + if s.Separator == separator { + keyPrefix += s.Separator + s.Prefix + } else { + keyPrefix += s.Prefix + } } if s.Deployment != "" { keyPrefix += s.Separator + s.Deployment From ce20f333eb9c01f6e7ad0b0711bf22b68d6cc43e Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 12:47:54 +0800 Subject: [PATCH 44/70] improve code --- contrib/registry/polaris/.gitignore | 11 +++++++++++ contrib/registry/polaris/registry.go | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 contrib/registry/polaris/.gitignore diff --git a/contrib/registry/polaris/.gitignore b/contrib/registry/polaris/.gitignore new file mode 100644 index 00000000000..c13ec1d86b8 --- /dev/null +++ b/contrib/registry/polaris/.gitignore @@ -0,0 +1,11 @@ +### Example user template template +### Example user template + +# IntelliJ project files +.idea +*.iml +out +gen + +*.log +*.json \ No newline at end of file diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index 51b29d903cc..f34313d4b15 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -441,8 +441,24 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { if k, ok := metadata["kind"]; ok { kind = k } + + name := "" + names := strings.Split(instance.GetService(), _instanceIDSeparator) + if names != nil && len(names) > 4 { + return &gsvc.Service{ + Prefix: names[0], + Deployment: names[1], + Namespace: names[2], + Name: names[3], + Version: metadata["version"], + Metadata: gconv.Map(metadata), + Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())}, + Separator: _instanceIDSeparator, + } + } + return &gsvc.Service{ - Name: instance.GetService(), + Name: name, Version: metadata["version"], Metadata: gconv.Map(metadata), Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, instance.GetHost(), instance.GetPort())}, From c60ee80af8db44b7cf506284170acb9d0f2d8dbc Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 13:20:01 +0800 Subject: [PATCH 45/70] fix --- contrib/registry/polaris/registry_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index 55da28c9c8a..440ebbca1aa 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -138,11 +138,13 @@ func TestGetService(t *testing.T) { } time.Sleep(time.Second * 1) serviceInstances, err := r.Search(ctx, gsvc.SearchInput{ - Name: svc.Name, - Version: svc.Version, - Metadata: svc.Metadata, - Endpoints: svc.Endpoints, - Separator: _instanceIDSeparator, + Prefix: svc.Prefix, + Deployment: svc.Deployment, + Namespace: svc.Namespace, + Name: svc.Name, + Version: svc.Version, + Metadata: svc.Metadata, + Endpoints: svc.Endpoints, }) if err != nil { t.Fatal(err) From defc46acc9f669145dfb3c8f718b183593965aea Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 13:42:14 +0800 Subject: [PATCH 46/70] up --- net/ghttp/ghttp_server_router_serve.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ghttp/ghttp_server_router_serve.go b/net/ghttp/ghttp_server_router_serve.go index 3892f9b661a..d1a82905f9f 100644 --- a/net/ghttp/ghttp_server_router_serve.go +++ b/net/ghttp/ghttp_server_router_serve.go @@ -56,7 +56,7 @@ func (s *Server) getHandlersWithCache(r *Request) (parsedItems []*handlerParsedI if xUrlPath := r.Header.Get(HeaderXUrlPath); xUrlPath != "" { path = xUrlPath } - + handlerCacheKey := s.serveHandlerKey(method, path, host) value, err := s.serveCache.GetOrSetFunc(ctx, handlerCacheKey, func(ctx context.Context) (interface{}, error) { parsedItems, hasHook, hasServe = s.searchHandlers(method, path, host) From 2ac6b489486d41df206aa9e4d5b4296dd44e6ae0 Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 13:52:19 +0800 Subject: [PATCH 47/70] feat: #1826 --- net/gclient/gclient_discovery.go | 3 +-- net/gclient/gclient_dump.go | 2 +- net/gclient/gclient_middleware.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/net/gclient/gclient_discovery.go b/net/gclient/gclient_discovery.go index 5bded4afacc..3debb5a6b56 100644 --- a/net/gclient/gclient_discovery.go +++ b/net/gclient/gclient_discovery.go @@ -52,7 +52,7 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response intlog.Printf(ctx, `http client watching service "%s" changed`, service.KeyWithoutEndpoints()) if v := clientSelectorMap.Get(service.KeyWithoutEndpoints()); v != nil { if err = updateSelectorNodesByService(v.(gsel.Selector), service); err != nil { - intlog.Errorf(context.Background(), `%+w`, err) + intlog.Errorf(context.Background(), `%+v`, err) } } }) @@ -76,7 +76,6 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response // Pick one node from multiple addresses. node, done, err := selector.Pick(ctx) if err != nil { - return nil, err } if done != nil { diff --git a/net/gclient/gclient_dump.go b/net/gclient/gclient_dump.go index 51750d05a42..c96bf4a1117 100644 --- a/net/gclient/gclient_dump.go +++ b/net/gclient/gclient_dump.go @@ -16,7 +16,7 @@ import ( "github.com/gogf/gf/v2/internal/utils" ) -// dumpTextFormat is the format of the dumped raw string +// dumpTextFormat is the format of the dumped raw string. const dumpTextFormat = `+---------------------------------------------+ | %s | +---------------------------------------------+ diff --git a/net/gclient/gclient_middleware.go b/net/gclient/gclient_middleware.go index 010ba30bbcc..449b602b9f2 100644 --- a/net/gclient/gclient_middleware.go +++ b/net/gclient/gclient_middleware.go @@ -6,7 +6,7 @@ import ( "github.com/gogf/gf/v2/os/gctx" ) -// HandlerFunc middleware handler func +// HandlerFunc middleware handler func. type HandlerFunc = func(c *Client, r *http.Request) (*Response, error) // clientMiddleware is the plugin for http client request workflow management. From 9424f111dce41779446c711e56a5433de36ff23a Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 17:11:46 +0800 Subject: [PATCH 48/70] up --- example/go.sum | 34 ++++++++++++---------------------- go.mod | 2 +- go.sum | 43 ++++++++++++------------------------------- 3 files changed, 25 insertions(+), 54 deletions(-) diff --git a/example/go.sum b/example/go.sum index 286bfd4dff8..e53038b0b1b 100644 --- a/example/go.sum +++ b/example/go.sum @@ -117,10 +117,6 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= -github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= -github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -327,14 +323,14 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM= go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E= @@ -346,8 +342,6 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= -go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y= go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= @@ -379,7 +373,6 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U 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-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -412,9 +405,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= -golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= 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= @@ -446,15 +438,14 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -521,15 +512,14 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -540,8 +530,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 h1:dejsXyH3RsgJiGtZB8yNSjsPzZU/hAJ8aMJmRi7+Dtk= -golang.org/x/text v0.3.8-0.20220428233042-78819d01d041/go.mod h1:UqJy94PED2GK2o3pz2dHDKz1s05DEJMG9tubaZ3t0uI= +golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= +golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -591,8 +581,8 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= -golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= +golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= 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= diff --git a/go.mod b/go.mod index 1760f59ca3a..888bde267f3 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( go.opentelemetry.io/otel/sdk v1.7.0 go.opentelemetry.io/otel/trace v1.7.0 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 - golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba // indirect + golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba // indirect golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) diff --git a/go.sum b/go.sum index d5df485e627..aca26cfa3a2 100644 --- a/go.sum +++ b/go.sum @@ -18,17 +18,13 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= -github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= -github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= -github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= @@ -44,10 +40,9 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/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/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= @@ -85,13 +80,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= -go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= -go.opentelemetry.io/otel/sdk v1.0.0 h1:BNPMYUONPNbLneMttKSjQhOTlFLOD9U22HNG1KrIN2Y= -go.opentelemetry.io/otel/sdk v1.0.0/go.mod h1:PCrDHlSy5x1kjezSdL37PhbFUMjrsLRshJ2zCzeXwbM= -go.opentelemetry.io/otel/trace v1.0.0 h1:TSBr8GTEtKevYMG/2d21M989r5WJYVimhTHBKVEZuh4= -go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= @@ -102,19 +90,17 @@ go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.3.0/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.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -134,28 +120,23 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 h1:dejsXyH3RsgJiGtZB8yNSjsPzZU/hAJ8aMJmRi7+Dtk= -golang.org/x/text v0.3.8-0.20220428233042-78819d01d041/go.mod h1:UqJy94PED2GK2o3pz2dHDKz1s05DEJMG9tubaZ3t0uI= +golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= +golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= 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= From 84dbb3bacac9cd520c2ce4ea7ba0f08a5ea0805d Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 21:29:41 +0800 Subject: [PATCH 49/70] up --- net/gclient/gclient_config.go | 4 ++-- net/gclient/gclient_discovery.go | 4 ++-- net/gclient/gclient_dump.go | 2 +- net/gclient/gclient_middleware.go | 2 +- net/gclient/gclient_tracing.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/net/gclient/gclient_config.go b/net/gclient/gclient_config.go index 01109562dfa..73c801ccc6a 100644 --- a/net/gclient/gclient_config.go +++ b/net/gclient/gclient_config.go @@ -112,7 +112,7 @@ func (c *Client) SetRetry(retryCount int, retryInterval time.Duration) *Client { return c } -// SetRedirectLimit limit the number of jumps. +// SetRedirectLimit limit the number of jumps func (c *Client) SetRedirectLimit(redirectLimit int) *Client { c.CheckRedirect = func(req *http.Request, via []*http.Request) error { if len(via) >= redirectLimit { @@ -141,7 +141,7 @@ func (c *Client) SetProxy(proxyURL string) { v.Proxy = http.ProxyURL(_proxy) } } else { - auth := &proxy.Auth{} + var auth = &proxy.Auth{} user := _proxy.User.Username() if user != "" { auth.User = user diff --git a/net/gclient/gclient_discovery.go b/net/gclient/gclient_discovery.go index 3debb5a6b56..a276e6b3125 100644 --- a/net/gclient/gclient_discovery.go +++ b/net/gclient/gclient_discovery.go @@ -38,7 +38,7 @@ var clientSelectorMap = gmap.New(true) // internalMiddlewareDiscovery is a client middleware that enables service discovery feature for client. func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response, err error) { - ctx := r.Context() + var ctx = r.Context() // Mark this request is handled by server tracing middleware, // to avoid repeated handling by the same middleware. if ctx.Value(discoveryMiddlewareHandled) != nil { @@ -63,7 +63,7 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response return c.Next(r) } // Balancer. - selectorMapKey := service.KeyWithoutEndpoints() + var selectorMapKey = service.KeyWithoutEndpoints() selector := clientSelectorMap.GetOrSetFuncLock(selectorMapKey, func() interface{} { intlog.Printf(ctx, `http client create selector for service "%s"`, selectorMapKey) diff --git a/net/gclient/gclient_dump.go b/net/gclient/gclient_dump.go index c96bf4a1117..51750d05a42 100644 --- a/net/gclient/gclient_dump.go +++ b/net/gclient/gclient_dump.go @@ -16,7 +16,7 @@ import ( "github.com/gogf/gf/v2/internal/utils" ) -// dumpTextFormat is the format of the dumped raw string. +// dumpTextFormat is the format of the dumped raw string const dumpTextFormat = `+---------------------------------------------+ | %s | +---------------------------------------------+ diff --git a/net/gclient/gclient_middleware.go b/net/gclient/gclient_middleware.go index 449b602b9f2..010ba30bbcc 100644 --- a/net/gclient/gclient_middleware.go +++ b/net/gclient/gclient_middleware.go @@ -6,7 +6,7 @@ import ( "github.com/gogf/gf/v2/os/gctx" ) -// HandlerFunc middleware handler func. +// HandlerFunc middleware handler func type HandlerFunc = func(c *Client, r *http.Request) (*Response, error) // clientMiddleware is the plugin for http client request workflow management. diff --git a/net/gclient/gclient_tracing.go b/net/gclient/gclient_tracing.go index b58f074b1e5..da17c0866b6 100644 --- a/net/gclient/gclient_tracing.go +++ b/net/gclient/gclient_tracing.go @@ -48,7 +48,7 @@ const ( // internalMiddlewareTracing is a client middleware that enables tracing feature using standards of OpenTelemetry. func internalMiddlewareTracing(c *Client, r *http.Request) (response *Response, err error) { - ctx := r.Context() + var ctx = r.Context() // Mark this request is handled by server tracing middleware, // to avoid repeated handling by the same middleware. if ctx.Value(tracingMiddlewareHandled) != nil { From 734f85cae33fe069464b662c7303a6e9e5f51f0f Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 21:34:05 +0800 Subject: [PATCH 50/70] improve comment for gclient --- net/gclient/gclient_config.go | 4 ++-- net/gclient/gclient_discovery.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/net/gclient/gclient_config.go b/net/gclient/gclient_config.go index 73c801ccc6a..493724d36dc 100644 --- a/net/gclient/gclient_config.go +++ b/net/gclient/gclient_config.go @@ -112,7 +112,7 @@ func (c *Client) SetRetry(retryCount int, retryInterval time.Duration) *Client { return c } -// SetRedirectLimit limit the number of jumps +// SetRedirectLimit limits the number of jumps. func (c *Client) SetRedirectLimit(redirectLimit int) *Client { c.CheckRedirect = func(req *http.Request, via []*http.Request) error { if len(via) >= redirectLimit { @@ -141,7 +141,7 @@ func (c *Client) SetProxy(proxyURL string) { v.Proxy = http.ProxyURL(_proxy) } } else { - var auth = &proxy.Auth{} + auth := &proxy.Auth{} user := _proxy.User.Username() if user != "" { auth.User = user diff --git a/net/gclient/gclient_discovery.go b/net/gclient/gclient_discovery.go index a276e6b3125..edfeb3ed6f9 100644 --- a/net/gclient/gclient_discovery.go +++ b/net/gclient/gclient_discovery.go @@ -26,10 +26,12 @@ type discoveryNode struct { address string } +// Service is the client discovery service. func (n *discoveryNode) Service() *gsvc.Service { return n.service } +// Address returns the address of the node. func (n *discoveryNode) Address() string { return n.address } @@ -38,7 +40,7 @@ var clientSelectorMap = gmap.New(true) // internalMiddlewareDiscovery is a client middleware that enables service discovery feature for client. func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response, err error) { - var ctx = r.Context() + ctx := r.Context() // Mark this request is handled by server tracing middleware, // to avoid repeated handling by the same middleware. if ctx.Value(discoveryMiddlewareHandled) != nil { @@ -63,10 +65,9 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response return c.Next(r) } // Balancer. - var selectorMapKey = service.KeyWithoutEndpoints() + selectorMapKey := service.KeyWithoutEndpoints() selector := clientSelectorMap.GetOrSetFuncLock(selectorMapKey, func() interface{} { intlog.Printf(ctx, `http client create selector for service "%s"`, selectorMapKey) - return gsel.GetBuilder().Build() }).(gsel.Selector) // Update selector nodes. From 30a3d362af0f6a8c93d433fe6e4f0425de8d7fed Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 21:58:18 +0800 Subject: [PATCH 51/70] up --- net/ghttp/ghttp_middleware_tracing.go | 4 ++-- net/ghttp/ghttp_request_middleware.go | 4 ++-- net/ghttp/ghttp_request_param.go | 6 ++++-- net/ghttp/ghttp_request_param_request.go | 4 +++- net/ghttp/ghttp_response.go | 4 +++- net/ghttp/ghttp_server.go | 8 ++++---- net/ghttp/ghttp_server_admin.go | 2 +- net/ghttp/ghttp_server_admin_process.go | 10 +++++++--- net/ghttp/ghttp_server_config.go | 2 +- net/ghttp/ghttp_server_cookie.go | 2 +- net/ghttp/ghttp_server_openapi.go | 4 +++- net/ghttp/ghttp_server_registry.go | 2 +- net/ghttp/ghttp_server_router.go | 14 ++++++++------ net/ghttp/ghttp_server_router_group.go | 4 +++- net/ghttp/ghttp_server_router_middleware.go | 8 ++++++-- net/ghttp/ghttp_server_router_serve.go | 4 ++-- net/ghttp/ghttp_server_service_handler.go | 4 ++-- net/ghttp/ghttp_server_service_object.go | 2 +- net/ghttp/ghttp_server_status.go | 2 +- 19 files changed, 55 insertions(+), 35 deletions(-) diff --git a/net/ghttp/ghttp_middleware_tracing.go b/net/ghttp/ghttp_middleware_tracing.go index 52f8dff61e9..84abc7dc8cf 100644 --- a/net/ghttp/ghttp_middleware_tracing.go +++ b/net/ghttp/ghttp_middleware_tracing.go @@ -40,7 +40,7 @@ const ( // internalMiddlewareServerTracing is a serer middleware that enables tracing feature using standards of OpenTelemetry. func internalMiddlewareServerTracing(r *Request) { - ctx := r.Context() + var ctx = r.Context() // Mark this request is handled by server tracing middleware, // to avoid repeated handling by the same middleware. if ctx.Value(tracingMiddlewareHandled) != nil { @@ -99,7 +99,7 @@ func internalMiddlewareServerTracing(r *Request) { span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, err)) } // Response content logging. - resBodyContent := gstr.StrLimit(r.Response.BufferString(), gtrace.MaxContentLogSize(), "...") + var resBodyContent = gstr.StrLimit(r.Response.BufferString(), gtrace.MaxContentLogSize(), "...") span.AddEvent(tracingEventHttpResponse, trace.WithAttributes( attribute.String(tracingEventHttpResponseHeaders, gconv.String(httputil.HeaderToMap(r.Response.Header()))), diff --git a/net/ghttp/ghttp_request_middleware.go b/net/ghttp/ghttp_request_middleware.go index 45de7b4e9cc..0b5cf8454ee 100644 --- a/net/ghttp/ghttp_request_middleware.go +++ b/net/ghttp/ghttp_request_middleware.go @@ -27,7 +27,7 @@ type middleware struct { // It's an important function controlling the workflow of the server request execution. func (m *middleware) Next() { var item *handlerParsedItem - loop := true + var loop = true for loop { // Check whether the request is excited. if m.request.IsExited() || m.handlerIndex >= len(m.request.handlers) { @@ -129,7 +129,7 @@ func (m *middleware) callHandlerFunc(funcInfo handlerFuncInfo) { if funcInfo.Func != nil { funcInfo.Func(m.request) } else { - inputValues := []reflect.Value{ + var inputValues = []reflect.Value{ reflect.ValueOf(m.request.Context()), } if funcInfo.Type.NumIn() == 2 { diff --git a/net/ghttp/ghttp_request_param.go b/net/ghttp/ghttp_request_param.go index f5887b9aa27..936dc4dc87b 100644 --- a/net/ghttp/ghttp_request_param.go +++ b/net/ghttp/ghttp_request_param.go @@ -35,8 +35,10 @@ const ( parseTypeForm = 2 ) -// xmlHeaderBytes is the most common XML format header. -var xmlHeaderBytes = []byte(" 0 && kvMap[0] != nil { filter = true } diff --git a/net/ghttp/ghttp_response.go b/net/ghttp/ghttp_response.go index 6ed50fae8b3..e696a4f54fa 100644 --- a/net/ghttp/ghttp_response.go +++ b/net/ghttp/ghttp_response.go @@ -42,7 +42,9 @@ func newResponse(s *Server, w http.ResponseWriter) *Response { // ServeFile serves the file to the response. func (r *Response) ServeFile(path string, allowIndex ...bool) { - var serveFile *staticFile + var ( + serveFile *staticFile + ) if file := gres.Get(path); file != nil { serveFile = &staticFile{ File: file, diff --git a/net/ghttp/ghttp_server.go b/net/ghttp/ghttp_server.go index d43c53bf9d0..3dd2500c77e 100644 --- a/net/ghttp/ghttp_server.go +++ b/net/ghttp/ghttp_server.go @@ -47,7 +47,7 @@ func init() { // serverProcessInit initializes some process configurations, which can only be done once. func serverProcessInit() { - ctx := context.TODO() + var ctx = context.TODO() if !serverProcessInitialized.Cas(false, true) { return } @@ -121,7 +121,7 @@ func GetServer(name ...interface{}) *Server { // Start starts listening on configured port. // This function does not block the process, you can use function Wait blocking the process. func (s *Server) Start() error { - ctx := context.TODO() + var ctx = context.TODO() // Swagger UI. if s.config.SwaggerPath != "" { @@ -414,7 +414,7 @@ func (s *Server) GetRoutes() []RouterItem { // Run starts server listening in blocking way. // It's commonly used for single server situation. func (s *Server) Run() { - ctx := context.TODO() + var ctx = context.TODO() if err := s.Start(); err != nil { s.Logger().Fatalf(ctx, `%+v`, err) @@ -437,7 +437,7 @@ func (s *Server) Run() { // Wait blocks to wait for all servers done. // It's commonly used in multiple server situation. func Wait() { - ctx := context.TODO() + var ctx = context.TODO() <-allDoneChan // Remove plugins. diff --git a/net/ghttp/ghttp_server_admin.go b/net/ghttp/ghttp_server_admin.go index 3d2e29007fe..df3553994b7 100644 --- a/net/ghttp/ghttp_server_admin.go +++ b/net/ghttp/ghttp_server_admin.go @@ -88,7 +88,7 @@ func (s *Server) EnableAdmin(pattern ...string) { // Shutdown shuts down current server. func (s *Server) Shutdown() error { - ctx := context.TODO() + var ctx = context.TODO() // Only shut down current servers. // It may have multiple underlying http servers. for _, v := range s.servers { diff --git a/net/ghttp/ghttp_server_admin_process.go b/net/ghttp/ghttp_server_admin_process.go index c4bb138d915..1b841300397 100644 --- a/net/ghttp/ghttp_server_admin_process.go +++ b/net/ghttp/ghttp_server_admin_process.go @@ -114,7 +114,9 @@ func checkActionFrequency() error { // forkReloadProcess creates a new child process and copies the fd to child process. func forkReloadProcess(ctx context.Context, newExeFilePath ...string) error { - path := os.Args[0] + var ( + path = os.Args[0] + ) if len(newExeFilePath) > 0 { path = newExeFilePath[0] } @@ -155,7 +157,9 @@ func forkReloadProcess(ctx context.Context, newExeFilePath ...string) error { // forkRestartProcess creates a new server process. func forkRestartProcess(ctx context.Context, newExeFilePath ...string) error { - path := os.Args[0] + var ( + path = os.Args[0] + ) if len(newExeFilePath) > 0 { path = newExeFilePath[0] } @@ -285,7 +289,7 @@ func forceCloseWebServers(ctx context.Context) { // handleProcessMessage receives and handles the message from processes, // which are commonly used for graceful reloading feature. func handleProcessMessage() { - ctx := context.TODO() + var ctx = context.TODO() for { if msg := gproc.Receive(adminGProcCommGroup); msg != nil { if bytes.EqualFold(msg.Data, []byte("exit")) { diff --git a/net/ghttp/ghttp_server_config.go b/net/ghttp/ghttp_server_config.go index 1bac3e8166a..89eb8028808 100644 --- a/net/ghttp/ghttp_server_config.go +++ b/net/ghttp/ghttp_server_config.go @@ -440,7 +440,7 @@ func (s *Server) SetListener(listeners ...net.Listener) error { // EnableHTTPS enables HTTPS with given certification and key files for the server. // The optional parameter `tlsConfig` specifies custom TLS configuration. func (s *Server) EnableHTTPS(certFile, keyFile string, tlsConfig ...*tls.Config) { - ctx := context.TODO() + var ctx = context.TODO() certFileRealPath := gfile.RealPath(certFile) if certFileRealPath == "" { certFileRealPath = gfile.RealPath(gfile.Pwd() + gfile.Separator + certFile) diff --git a/net/ghttp/ghttp_server_cookie.go b/net/ghttp/ghttp_server_cookie.go index 5164d9f464c..b5e618ba0ce 100644 --- a/net/ghttp/ghttp_server_cookie.go +++ b/net/ghttp/ghttp_server_cookie.go @@ -21,7 +21,7 @@ type Cookie struct { response *Response // Belonged HTTP response. } -// CookieOptions provides security config for cookies. +// CookieOptions provides security config for cookies type CookieOptions struct { SameSite http.SameSite // cookie SameSite property Secure bool // cookie Secure property diff --git a/net/ghttp/ghttp_server_openapi.go b/net/ghttp/ghttp_server_openapi.go index f73d0b0d5d9..035063f0434 100644 --- a/net/ghttp/ghttp_server_openapi.go +++ b/net/ghttp/ghttp_server_openapi.go @@ -48,7 +48,9 @@ func (s *Server) initOpenApi() { // openapiSpec is a build-in handler automatic producing for openapi specification json file. func (s *Server) openapiSpec(r *Request) { - var err error + var ( + err error + ) if s.config.OpenApiPath == "" { r.Response.Write(`OpenApi specification file producing is disabled`) } else { diff --git a/net/ghttp/ghttp_server_registry.go b/net/ghttp/ghttp_server_registry.go index 87cddf862ae..8a6d5989a05 100644 --- a/net/ghttp/ghttp_server_registry.go +++ b/net/ghttp/ghttp_server_registry.go @@ -61,7 +61,7 @@ func (s *Server) doServiceDeregister() { if gsvc.GetRegistry() == nil { return } - ctx := context.Background() + var ctx = context.Background() s.Logger().Debugf(ctx, `service deregister: %+v`, s.service) if err := gsvc.Deregister(ctx, s.service); err != nil { s.Logger().Errorf(ctx, `%+v`, err) diff --git a/net/ghttp/ghttp_server_router.go b/net/ghttp/ghttp_server_router.go index 41b230c739d..973ac35a854 100644 --- a/net/ghttp/ghttp_server_router.go +++ b/net/ghttp/ghttp_server_router.go @@ -29,8 +29,10 @@ const ( stackFilterKey = "/net/ghttp/ghttp" ) -// handlerIdGenerator is handler item id generator. -var handlerIdGenerator = gtype.NewInt() +var ( + // handlerIdGenerator is handler item id generator. + handlerIdGenerator = gtype.NewInt() +) // routerMapKey creates and returns a unique router key for given parameters. // This key is used for Server.routerMap attribute, which is mainly for checks for @@ -97,7 +99,7 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { // Change the registered route according to meta info from its request structure. if handler.Info.Type != nil && handler.Info.Type.NumIn() == 2 { - objectReq := reflect.New(handler.Info.Type.In(1)) + var objectReq = reflect.New(handler.Info.Type.In(1)) if v := gmeta.Get(objectReq, goai.TagNamePath); !v.IsEmpty() { uri = v.String() } @@ -124,7 +126,7 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { } // Repeated router checks, this feature can be disabled by server configuration. - routerKey := s.routerMapKey(handler.HookName, method, uri, domain) + var routerKey = s.routerMapKey(handler.HookName, method, uri, domain) if !s.config.RouteOverWrite { switch handler.Type { case HandlerTypeHandler, HandlerTypeObject: @@ -182,7 +184,7 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) { // priorities from high to low. // 3. There may be repeated router items in the router lists. The lists' priorities // from root to leaf are from low to high. - p := s.serveTree[domain] + var p = s.serveTree[domain] for i, part := range array { // Ignore empty URI part, like: /user//index if part == "" { @@ -387,7 +389,7 @@ func (s *Server) patternToRegular(rule string) (regular string, names []string) return rule, nil } regular = "^" - array := strings.Split(rule[1:], "/") + var array = strings.Split(rule[1:], "/") for _, v := range array { if len(v) == 0 { continue diff --git a/net/ghttp/ghttp_server_router_group.go b/net/ghttp/ghttp_server_router_group.go index 65e3568bbeb..8d6b4de585a 100644 --- a/net/ghttp/ghttp_server_router_group.go +++ b/net/ghttp/ghttp_server_router_group.go @@ -48,7 +48,9 @@ const ( groupBindTypeMiddleware = "MIDDLEWARE" ) -var preBindItems = make([]*preBindItem, 0, 64) +var ( + preBindItems = make([]*preBindItem, 0, 64) +) // handlePreBindItems is called when server starts, which does really route registering to the server. func (s *Server) handlePreBindItems(ctx context.Context) { diff --git a/net/ghttp/ghttp_server_router_middleware.go b/net/ghttp/ghttp_server_router_middleware.go index 1b33ee8b53a..cf4adfc9deb 100644 --- a/net/ghttp/ghttp_server_router_middleware.go +++ b/net/ghttp/ghttp_server_router_middleware.go @@ -23,7 +23,9 @@ const ( // before or after service handler. The parameter `pattern` specifies what route pattern the middleware intercepts, // which is usually a "fuzzy" pattern like "/:name", "/*any" or "/{field}". func (s *Server) BindMiddleware(pattern string, handlers ...HandlerFunc) { - ctx := context.TODO() + var ( + ctx = context.TODO() + ) for _, handler := range handlers { s.setHandler(ctx, setHandlerInput{ Prefix: "", @@ -44,7 +46,9 @@ func (s *Server) BindMiddleware(pattern string, handlers ...HandlerFunc) { // Global middleware can be used standalone without service handler, which intercepts all dynamic requests // before or after service handler. func (s *Server) BindMiddlewareDefault(handlers ...HandlerFunc) { - ctx := context.TODO() + var ( + ctx = context.TODO() + ) for _, handler := range handlers { s.setHandler(ctx, setHandlerInput{ Prefix: "", diff --git a/net/ghttp/ghttp_server_router_serve.go b/net/ghttp/ghttp_server_router_serve.go index d1a82905f9f..3f1e9cb5f0e 100644 --- a/net/ghttp/ghttp_server_router_serve.go +++ b/net/ghttp/ghttp_server_router_serve.go @@ -57,7 +57,7 @@ func (s *Server) getHandlersWithCache(r *Request) (parsedItems []*handlerParsedI path = xUrlPath } - handlerCacheKey := s.serveHandlerKey(method, path, host) + var handlerCacheKey = s.serveHandlerKey(method, path, host) value, err := s.serveCache.GetOrSetFunc(ctx, handlerCacheKey, func(ctx context.Context) (interface{}, error) { parsedItems, hasHook, hasServe = s.searchHandlers(method, path, host) if parsedItems != nil { @@ -83,7 +83,7 @@ func (s *Server) searchHandlers(method, path, domain string) (parsedItems []*han } // In case of double '/' URI, for example: // /user//index, //user/index, //user//index// - previousIsSep := false + var previousIsSep = false for i := 0; i < len(path); { if path[i] == '/' { if previousIsSep { diff --git a/net/ghttp/ghttp_server_service_handler.go b/net/ghttp/ghttp_server_service_handler.go index 39767fb44e6..782577e3f34 100644 --- a/net/ghttp/ghttp_server_service_handler.go +++ b/net/ghttp/ghttp_server_service_handler.go @@ -23,7 +23,7 @@ import ( // 1. func(*ghttp.Request) // 2. func(context.Context, BizRequest)(BizResponse, error). func (s *Server) BindHandler(pattern string, handler interface{}) { - ctx := context.TODO() + var ctx = context.TODO() funcInfo, err := s.checkAndCreateFuncInfo(handler, "", "", "") if err != nil { s.Logger().Fatalf(ctx, `%+v`, err) @@ -48,7 +48,7 @@ type doBindHandlerInput struct { // doBindHandler registers a handler function to server with given pattern. // // The parameter `pattern` is like: -// /user/list, put:/user, delete:/user, post:/user@goframe.org. +// /user/list, put:/user, delete:/user, post:/user@goframe.org func (s *Server) doBindHandler(ctx context.Context, in doBindHandlerInput) { s.setHandler(ctx, setHandlerInput{ Prefix: in.Prefix, diff --git a/net/ghttp/ghttp_server_service_object.go b/net/ghttp/ghttp_server_service_object.go index 73d95f58453..8842841ab46 100644 --- a/net/ghttp/ghttp_server_service_object.go +++ b/net/ghttp/ghttp_server_service_object.go @@ -22,7 +22,7 @@ import ( // The optional parameter `method` is used to specify the method to be registered, which // supports multiple method names; multiple methods are separated by char ',', case-sensitive. func (s *Server) BindObject(pattern string, object interface{}, method ...string) { - bindMethod := "" + var bindMethod = "" if len(method) > 0 { bindMethod = method[0] } diff --git a/net/ghttp/ghttp_server_status.go b/net/ghttp/ghttp_server_status.go index 783b4f6bb25..3fbd146b4bc 100644 --- a/net/ghttp/ghttp_server_status.go +++ b/net/ghttp/ghttp_server_status.go @@ -22,7 +22,7 @@ func (s *Server) getStatusHandler(status int, r *Request) []HandlerFunc { } // addStatusHandler sets the handler for given status code. -// The parameter `pattern` is like: domain#status. +// The parameter `pattern` is like: domain#status func (s *Server) addStatusHandler(pattern string, handler HandlerFunc) { if s.statusHandlerMap[pattern] == nil { s.statusHandlerMap[pattern] = make([]HandlerFunc, 0) From 17ed325db7ba21a099f5d5455febe66d37672999 Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 22:01:14 +0800 Subject: [PATCH 52/70] fix --- net/ghttp/ghttp_middleware_tracing.go | 4 +++- net/ghttp/ghttp_server_admin.go | 4 +++- net/ghttp/ghttp_server_admin_process.go | 4 +++- net/ghttp/ghttp_server_router_serve.go | 1 - net/ghttp/ghttp_server_service_handler.go | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/net/ghttp/ghttp_middleware_tracing.go b/net/ghttp/ghttp_middleware_tracing.go index 84abc7dc8cf..1a2bf2095e9 100644 --- a/net/ghttp/ghttp_middleware_tracing.go +++ b/net/ghttp/ghttp_middleware_tracing.go @@ -40,7 +40,9 @@ const ( // internalMiddlewareServerTracing is a serer middleware that enables tracing feature using standards of OpenTelemetry. func internalMiddlewareServerTracing(r *Request) { - var ctx = r.Context() + var ( + ctx = r.Context() + ) // Mark this request is handled by server tracing middleware, // to avoid repeated handling by the same middleware. if ctx.Value(tracingMiddlewareHandled) != nil { diff --git a/net/ghttp/ghttp_server_admin.go b/net/ghttp/ghttp_server_admin.go index df3553994b7..e84d8d88639 100644 --- a/net/ghttp/ghttp_server_admin.go +++ b/net/ghttp/ghttp_server_admin.go @@ -88,7 +88,9 @@ func (s *Server) EnableAdmin(pattern ...string) { // Shutdown shuts down current server. func (s *Server) Shutdown() error { - var ctx = context.TODO() + var ( + ctx = context.TODO() + ) // Only shut down current servers. // It may have multiple underlying http servers. for _, v := range s.servers { diff --git a/net/ghttp/ghttp_server_admin_process.go b/net/ghttp/ghttp_server_admin_process.go index 1b841300397..fffe50ae83d 100644 --- a/net/ghttp/ghttp_server_admin_process.go +++ b/net/ghttp/ghttp_server_admin_process.go @@ -289,7 +289,9 @@ func forceCloseWebServers(ctx context.Context) { // handleProcessMessage receives and handles the message from processes, // which are commonly used for graceful reloading feature. func handleProcessMessage() { - var ctx = context.TODO() + var ( + ctx = context.TODO() + ) for { if msg := gproc.Receive(adminGProcCommGroup); msg != nil { if bytes.EqualFold(msg.Data, []byte("exit")) { diff --git a/net/ghttp/ghttp_server_router_serve.go b/net/ghttp/ghttp_server_router_serve.go index 3f1e9cb5f0e..0a2b214f132 100644 --- a/net/ghttp/ghttp_server_router_serve.go +++ b/net/ghttp/ghttp_server_router_serve.go @@ -56,7 +56,6 @@ func (s *Server) getHandlersWithCache(r *Request) (parsedItems []*handlerParsedI if xUrlPath := r.Header.Get(HeaderXUrlPath); xUrlPath != "" { path = xUrlPath } - var handlerCacheKey = s.serveHandlerKey(method, path, host) value, err := s.serveCache.GetOrSetFunc(ctx, handlerCacheKey, func(ctx context.Context) (interface{}, error) { parsedItems, hasHook, hasServe = s.searchHandlers(method, path, host) diff --git a/net/ghttp/ghttp_server_service_handler.go b/net/ghttp/ghttp_server_service_handler.go index 782577e3f34..25b4208f949 100644 --- a/net/ghttp/ghttp_server_service_handler.go +++ b/net/ghttp/ghttp_server_service_handler.go @@ -21,7 +21,7 @@ import ( // // Note that the parameter `handler` can be type of: // 1. func(*ghttp.Request) -// 2. func(context.Context, BizRequest)(BizResponse, error). +// 2. func(context.Context, BizRequest)(BizResponse, error) func (s *Server) BindHandler(pattern string, handler interface{}) { var ctx = context.TODO() funcInfo, err := s.checkAndCreateFuncInfo(handler, "", "", "") From 5508da44d4c3f85569311bf6a6c05925f57a38cd Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 22:19:30 +0800 Subject: [PATCH 53/70] improve code --- contrib/registry/etcd/etcd.go | 1 - contrib/registry/etcd/etcd_discovery.go | 5 ++- contrib/registry/etcd/etcd_registry.go | 2 +- contrib/registry/etcd/etcd_watcher.go | 5 ++- contrib/registry/polaris/registry_test.go | 1 - net/gsvc/gsvc.go | 2 - net/gsvc/gsvc_discovery.go | 9 ---- net/gsvc/gsvc_metadata.go | 3 +- net/gsvc/gsvc_search.go | 4 +- net/gsvc/gsvc_service.go | 52 +++++++++-------------- 10 files changed, 33 insertions(+), 51 deletions(-) diff --git a/contrib/registry/etcd/etcd.go b/contrib/registry/etcd/etcd.go index 7439cf70ddb..623e1e7ca75 100644 --- a/contrib/registry/etcd/etcd.go +++ b/contrib/registry/etcd/etcd.go @@ -42,7 +42,6 @@ type Option struct { const ( // DefaultKeepAliveTTL is the default keepalive TTL. DefaultKeepAliveTTL = 10 * time.Second - separator = "/" ) // New creates and returns a new etcd registry. diff --git a/contrib/registry/etcd/etcd_discovery.go b/contrib/registry/etcd/etcd_discovery.go index babd05f5c2d..1ad2f7f8514 100644 --- a/contrib/registry/etcd/etcd_discovery.go +++ b/contrib/registry/etcd/etcd_discovery.go @@ -9,10 +9,12 @@ package etcd import ( "context" - "github.com/gogf/gf/v2/net/gsvc" etcd3 "go.etcd.io/etcd/client/v3" + + "github.com/gogf/gf/v2/net/gsvc" ) +// Search is the etcd discovery search function. func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { res, err := r.kv.Get(ctx, in.Key(), etcd3.WithPrefix()) if err != nil { @@ -43,6 +45,7 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Ser return filteredServices, nil } +// Watch is the etcd discovery watch function. func (r *Registry) Watch(ctx context.Context, key string) (gsvc.Watcher, error) { return newWatcher(key, r.client) } diff --git a/contrib/registry/etcd/etcd_registry.go b/contrib/registry/etcd/etcd_registry.go index fc7cb92cc34..2a4baad0ede 100644 --- a/contrib/registry/etcd/etcd_registry.go +++ b/contrib/registry/etcd/etcd_registry.go @@ -43,7 +43,7 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { return err } go r.doKeepAlive(grant.ID, keepAliceCh) - service.Separator = separator + service.Separator = gsvc.Separator() return nil } diff --git a/contrib/registry/etcd/etcd_watcher.go b/contrib/registry/etcd/etcd_watcher.go index 49151068cfe..afeee375608 100644 --- a/contrib/registry/etcd/etcd_watcher.go +++ b/contrib/registry/etcd/etcd_watcher.go @@ -9,8 +9,9 @@ package etcd import ( "context" - "github.com/gogf/gf/v2/net/gsvc" etcd3 "go.etcd.io/etcd/client/v3" + + "github.com/gogf/gf/v2/net/gsvc" ) var ( @@ -41,6 +42,7 @@ func newWatcher(key string, client *etcd3.Client) (*watcher, error) { return w, nil } +// Proceed is used to watch the key. func (w *watcher) Proceed() ([]*gsvc.Service, error) { select { case <-w.ctx.Done(): @@ -50,6 +52,7 @@ func (w *watcher) Proceed() ([]*gsvc.Service, error) { } } +// Close is used to close the watcher. func (w *watcher) Close() error { w.cancel() return w.watcher.Close() diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/registry_test.go index 440ebbca1aa..98d62510949 100644 --- a/contrib/registry/polaris/registry_test.go +++ b/contrib/registry/polaris/registry_test.go @@ -144,7 +144,6 @@ func TestGetService(t *testing.T) { Name: svc.Name, Version: svc.Version, Metadata: svc.Metadata, - Endpoints: svc.Endpoints, }) if err != nil { t.Fatal(err) diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index c05cebf2b58..163b8c594d6 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -71,7 +71,6 @@ type SearchInput struct { Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. Name string // Name for the service. Version string // Service version, eg: v1.0.0, v2.1.1, etc.} - Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. Separator string // Separator for service name and version, eg: _, -, etc. } @@ -84,7 +83,6 @@ type WatchInput struct { Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. Name string // Name for the service. Version string // Service version, eg: v1.0.0, v2.1.1, etc.} - Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. Separator string // Separator for service name and version, eg: _, -, etc. } diff --git a/net/gsvc/gsvc_discovery.go b/net/gsvc/gsvc_discovery.go index 3528e1e30f3..5be3e64994d 100644 --- a/net/gsvc/gsvc_discovery.go +++ b/net/gsvc/gsvc_discovery.go @@ -35,14 +35,12 @@ func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service services []*Service watcher Watcher ) - services, err = Search(ctx, SearchInput{ Prefix: s.Prefix, Deployment: s.Deployment, Namespace: s.Namespace, Name: s.Name, Version: s.Version, - Endpoints: s.Endpoints, Metadata: s.Metadata, }) if err != nil { @@ -50,7 +48,6 @@ func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service } if len(services) == 0 { err = gerror.NewCodef(gcode.CodeNotFound, `service not found with name "%s"`, name) - return nil } service = services[0] @@ -59,15 +56,12 @@ func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service if err != nil { return nil } - go watchAndUpdateService(watcher, service, watch) - return service }) if v != nil { service = v.(*Service) } - return } @@ -82,7 +76,6 @@ func watchAndUpdateService(watcher Watcher, service *Service, watchFunc ServiceW services, err = watcher.Proceed() if err != nil { intlog.Errorf(ctx, `%+v`, err) - continue } if len(services) > 0 { @@ -104,7 +97,6 @@ func Search(ctx context.Context, in SearchInput) ([]*Service, error) { return nil, gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) } ctx, _ = context.WithTimeout(ctx, defaultTimeout) - return defaultRegistry.Search(ctx, in) } @@ -113,6 +105,5 @@ func Watch(ctx context.Context, key string) (Watcher, error) { if defaultRegistry == nil { return nil, gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) } - return defaultRegistry.Watch(ctx, key) } diff --git a/net/gsvc/gsvc_metadata.go b/net/gsvc/gsvc_metadata.go index 6a0251f5895..015c4432a8d 100644 --- a/net/gsvc/gsvc_metadata.go +++ b/net/gsvc/gsvc_metadata.go @@ -15,11 +15,10 @@ func (m Metadata) Set(key string, value string) { m[key] = value } -// Get retrieves and return value of specified key as gvar. +// Get retrieves and returns value of specified key as gvar. func (m Metadata) Get(key string) *gvar.Var { if v, ok := m[key]; ok { return gvar.New(v) } - return nil } diff --git a/net/gsvc/gsvc_search.go b/net/gsvc/gsvc_search.go index a13f85513f1..83b76dd7e9f 100644 --- a/net/gsvc/gsvc_search.go +++ b/net/gsvc/gsvc_search.go @@ -9,11 +9,11 @@ package gsvc // Key formats and returns a string for prefix searching purpose. func (s *SearchInput) Key() string { if s.Separator == "" { - s.Separator = separator + s.Separator = defaultSeparator } keyPrefix := "" if s.Prefix != "" { - if s.Separator == separator { + if s.Separator == defaultSeparator { keyPrefix += s.Separator + s.Prefix } else { keyPrefix += s.Prefix diff --git a/net/gsvc/gsvc_service.go b/net/gsvc/gsvc_service.go index 7fd1cd1107c..aabea49076f 100644 --- a/net/gsvc/gsvc_service.go +++ b/net/gsvc/gsvc_service.go @@ -19,18 +19,15 @@ import ( ) const ( - separator = "/" - delimiter = "," - - zero = 0 - one = 1 - two = 2 - three = 3 - four = 4 - five = 5 - six = 6 + defaultSeparator = "/" + delimiter = "," ) +// Separator is the default defaultSeparator for path. +func Separator() string { + return defaultSeparator +} + // NewServiceWithName creates and returns service from `name`. func NewServiceWithName(name string) (s *Service) { s = &Service{ @@ -38,47 +35,44 @@ func NewServiceWithName(name string) (s *Service) { Metadata: make(Metadata), } s.autoFillDefaultAttributes() - return } // NewServiceWithKV creates and returns service from `key` and `value`. func NewServiceWithKV(key, value []byte) (s *Service, err error) { - array := gstr.Split(gstr.Trim(string(key), separator), separator) - if len(array) < six { + array := gstr.Split(gstr.Trim(string(key), defaultSeparator), defaultSeparator) + if len(array) < 6 { err = gerror.NewCodef(gcode.CodeInvalidParameter, `invalid service key "%s"`, key) return } s = &Service{ - Prefix: array[zero], - Deployment: array[one], - Namespace: array[two], - Name: array[three], - Version: array[four], - Endpoints: gstr.Split(array[five], delimiter), + Prefix: array[0], + Deployment: array[1], + Namespace: array[2], + Name: array[3], + Version: array[4], + Endpoints: gstr.Split(array[5], delimiter), Metadata: make(Metadata), + Separator: defaultSeparator, } s.autoFillDefaultAttributes() - if len(value) > zero { + if len(value) > 0 { if err = gjson.Unmarshal(value, &s.Metadata); err != nil { err = gerror.WrapCodef(gcode.CodeInvalidParameter, err, `invalid service value "%s"`, value) - return nil, err } } - return s, nil } -// Key formats the service information and return the Service as registering key. +// Key formats the service information and returns the Service as registering key. func (s *Service) Key() string { if s.Separator == "" { - s.Separator = separator + s.Separator = defaultSeparator } serviceNameUnique := s.KeyWithoutEndpoints() serviceNameUnique += s.Separator + gstr.Join(s.Endpoints, ",") - return serviceNameUnique } @@ -91,13 +85,11 @@ func (s *Service) KeyWithSchema() string { func (s *Service) KeyWithoutEndpoints() string { s.autoFillDefaultAttributes() if s.Separator == "" { - s.Separator = separator + s.Separator = defaultSeparator } - - if s.Separator != separator { + if s.Separator != defaultSeparator { return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) } - return s.Separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) } @@ -107,7 +99,6 @@ func (s *Service) Value() string { if err != nil { intlog.Errorf(context.TODO(), `%+v`, err) } - return string(b) } @@ -117,7 +108,6 @@ func (s *Service) Address() string { if len(s.Endpoints) == 0 { return "" } - return s.Endpoints[0] } From a8bd6e9b97811be9410fed10f010e6c92ddf9ab6 Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 22:31:48 +0800 Subject: [PATCH 54/70] fix --- os/gstructs/gstructs_field.go | 8 ++--- text/gstr/gstr_case.go | 4 +-- text/gstr/gstr_parse.go | 2 +- text/gstr/gstr_similar.go | 2 +- text/gstr/gstr_slashes.go | 2 +- util/gvalid/gvalid.go | 2 +- util/gvalid/gvalid_custom_rule.go | 10 +++---- util/gvalid/gvalid_error.go | 4 +-- util/gvalid/gvalid_validator.go | 2 +- util/gvalid/gvalid_validator_check_struct.go | 22 +++++++------- util/gvalid/gvalid_validator_check_value.go | 29 +++++++++---------- util/gvalid/gvalid_validator_message.go | 2 +- util/gvalid/gvalid_validator_rule_luhn.go | 2 +- util/gvalid/gvalid_validator_rule_range.go | 1 - .../gvalid_validator_rule_resident_id.go | 2 +- 15 files changed, 44 insertions(+), 50 deletions(-) diff --git a/os/gstructs/gstructs_field.go b/os/gstructs/gstructs_field.go index b1a3ee64b1a..0583ddfd74c 100644 --- a/os/gstructs/gstructs_field.go +++ b/os/gstructs/gstructs_field.go @@ -50,7 +50,7 @@ func (f *Field) TagLookup(key string) (value string, ok bool) { return } -// IsEmbedded returns true if the given field is an anonymous field (embedded) +// IsEmbedded returns true if the given field is an anonymous field (embedded). func (f *Field) IsEmbedded() bool { return f.Field.Anonymous } @@ -62,9 +62,7 @@ func (f *Field) TagStr() string { // TagMap returns all the tag of the field along with its value string as map. func (f *Field) TagMap() map[string]string { - var ( - data = ParseTag(f.TagStr()) - ) + data := ParseTag(f.TagStr()) for k, v := range data { data[k] = utils.StripSlashes(gtag.Parse(v)) } @@ -107,7 +105,7 @@ func (f *Field) OriginalKind() reflect.Kind { return kind } -// Fields retrieve and return the fields of `pointer` as slice. +// Fields retrieve and returns the fields of `pointer` as slice. func Fields(in FieldsInput) ([]Field, error) { var ( ok bool diff --git a/text/gstr/gstr_case.go b/text/gstr/gstr_case.go index c07fff72627..d0a6e904591 100644 --- a/text/gstr/gstr_case.go +++ b/text/gstr/gstr_case.go @@ -83,7 +83,7 @@ func CaseSnakeFirstUpper(word string, underscore ...string) string { return TrimLeft(word, replace) } -// CaseKebab converts a string to kebab-case +// CaseKebab converts a string to kebab-case. func CaseKebab(s string) string { return CaseDelimited(s, '-') } @@ -154,7 +154,7 @@ func addWordBoundariesToNumbers(s string) string { return string(r) } -// Converts a string to CamelCase +// Converts a string to CamelCase. func toCamelInitCase(s string, initCase bool) string { s = addWordBoundariesToNumbers(s) s = strings.Trim(s, " ") diff --git a/text/gstr/gstr_parse.go b/text/gstr/gstr_parse.go index 4a95780a32c..632a0e242fc 100644 --- a/text/gstr/gstr_parse.go +++ b/text/gstr/gstr_parse.go @@ -23,7 +23,7 @@ import ( // v[a][]=m&v[a][]=n -> map[v:map[a:[m n]]] // v[][]=m&v[][]=n -> map[v:[map[]]] // Currently does not support nested slice. // v=m&v[a]=n -> error -// a .[[b=c -> map[a___[b:c] +// a .[[b=c -> map[a___[b:c]. // func Parse(s string) (result map[string]interface{}, err error) { if s == "" { diff --git a/text/gstr/gstr_similar.go b/text/gstr/gstr_similar.go index 7c19618fb6c..55d729726fd 100644 --- a/text/gstr/gstr_similar.go +++ b/text/gstr/gstr_similar.go @@ -12,7 +12,7 @@ package gstr // costDel: Defines the cost of deletion. // See http://php.net/manual/en/function.levenshtein.php. func Levenshtein(str1, str2 string, costIns, costRep, costDel int) int { - var maxLen = 255 + maxLen := 255 l1 := len(str1) l2 := len(str2) if l1 == 0 { diff --git a/text/gstr/gstr_slashes.go b/text/gstr/gstr_slashes.go index 1173047f7d7..2fed181462c 100644 --- a/text/gstr/gstr_slashes.go +++ b/text/gstr/gstr_slashes.go @@ -31,7 +31,7 @@ func StripSlashes(str string) string { } // QuoteMeta returns a version of str with a backslash character (\) -// before every character that is among: .\+*?[^]($). +// before every character that is among: .\+*?[^]($) func QuoteMeta(str string, chars ...string) string { var buf bytes.Buffer for _, char := range str { diff --git a/util/gvalid/gvalid.go b/util/gvalid/gvalid.go index 80373104fd9..122e560ac65 100644 --- a/util/gvalid/gvalid.go +++ b/util/gvalid/gvalid.go @@ -205,7 +205,7 @@ var ( ) // ParseTagValue parses one sequence tag to field, rule and error message. -// The sequence tag is like: [alias@]rule[...#msg...] +// The sequence tag is like: [alias@]rule[...#msg...]. func ParseTagValue(tag string) (field, rule, msg string) { // Complete sequence tag. // Example: name@required|length:2,20|password3|same:password1#||密码强度不足|两次密码不一致 diff --git a/util/gvalid/gvalid_custom_rule.go b/util/gvalid/gvalid_custom_rule.go index 9c5a9dfdd4c..315d2e36b55 100644 --- a/util/gvalid/gvalid_custom_rule.go +++ b/util/gvalid/gvalid_custom_rule.go @@ -35,11 +35,9 @@ type RuleFuncInput struct { Data *gvar.Var } -var ( - // customRuleFuncMap stores the custom rule functions. - // map[Rule]RuleFunc - customRuleFuncMap = make(map[string]RuleFunc) -) +// customRuleFuncMap stores the custom rule functions. +// map[Rule]RuleFunc. +var customRuleFuncMap = make(map[string]RuleFunc) // RegisterRule registers custom validation rules and function for package. func RegisterRule(rule string, f RuleFunc) { @@ -54,7 +52,7 @@ func RegisterRule(rule string, f RuleFunc) { customRuleFuncMap[rule] = f } -// RegisterRuleByMap registers custom validation rules using maps for package. +// RegisterRuleByMap registers custom validation rules using map for package. func RegisterRuleByMap(m map[string]RuleFunc) { for k, v := range m { customRuleFuncMap[k] = v diff --git a/util/gvalid/gvalid_error.go b/util/gvalid/gvalid_error.go index c489f710ee3..4d81a56c44d 100644 --- a/util/gvalid/gvalid_error.go +++ b/util/gvalid/gvalid_error.go @@ -54,7 +54,7 @@ func newValidationError(code gcode.Code, rules []fieldRule, fieldRuleErrorMap ma fieldRuleErrorMap[field] = ruleErrorMap } // Filter repeated sequence rules. - var ruleNameSet = gset.NewStrSet() + ruleNameSet := gset.NewStrSet() for i := 0; i < len(rules); { if !ruleNameSet.AddIfNotExist(rules[i].Name) { // Delete repeated rule. @@ -239,7 +239,7 @@ func (e *validationError) Strings() (errs []string) { } } // internal error checks. - for k, _ := range internalErrKeyMap { + for k := range internalErrKeyMap { if err, ok := errorItemMap[k]; ok { errs = append(errs, err.Error()) } diff --git a/util/gvalid/gvalid_validator.go b/util/gvalid/gvalid_validator.go index 944774f3cf4..99bc5ff3d30 100644 --- a/util/gvalid/gvalid_validator.go +++ b/util/gvalid/gvalid_validator.go @@ -125,7 +125,7 @@ func (v *Validator) Data(data interface{}) *Validator { // Assoc is a chaining operation function, which sets associated validation data for current operation. // The optional parameter `assoc` is usually type of map, which specifies the parameter map used in union validation. -// Calling this function with `assoc` also sets `useAssocInsteadOfObjectAttributes` true +// Calling this function with `assoc` also sets `useAssocInsteadOfObjectAttributes` true. func (v *Validator) Assoc(assoc interface{}) *Validator { if assoc == nil { return v diff --git a/util/gvalid/gvalid_validator_check_struct.go b/util/gvalid/gvalid_validator_check_struct.go index 1ae842b082e..8482ba19e00 100644 --- a/util/gvalid/gvalid_validator_check_struct.go +++ b/util/gvalid/gvalid_validator_check_struct.go @@ -36,7 +36,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error return newValidationErrorByStr(internalObjectErrRuleName, err) } - // It here must use gstructs.TagFields not gstructs.FieldMap to ensure error sequences. + // It here must use gstructs.TagFields not gstructs.FieldMap to ensure error sequence. tagFields, err := gstructs.TagFields(object, structTagPriority) if err != nil { return newValidationErrorByStr(internalObjectErrRuleName, err) @@ -51,7 +51,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error checkRules = make([]fieldRule, 0) nameToRuleMap = make(map[string]string) // just for internally searching index purpose. customMessage = make(CustomMsg) // Custom rule error message map. - checkValueData = v.assoc // Ready to be validated data, which can be types of. + checkValueData = v.assoc // Ready to be validated data, which can be type of. ) if checkValueData == nil { checkValueData = object @@ -71,7 +71,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error ruleArray = strings.Split(rule, "|") ) for k, ruleKey := range ruleArray { - // If the length of custom messages is less than the length of rules, + // If length of custom messages is lesser than length of rules, // the rest rules use the default error messages. if len(msgArray) <= k { continue @@ -93,7 +93,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error }) } - // Map type rule does not support sequences. + // Map type rules does not support sequence. // Format: map[key]rule case map[string]string: nameToRuleMap = assertValue @@ -114,7 +114,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error } else { inputParamMap = gconv.Map(v.assoc) } - // Checks and extend the parameter map with struct alias tag. + // Checks and extends the parameters map with struct alias tag. if !v.useAssocInsteadOfObjectAttributes { for nameOrTag, field := range fieldMap { inputParamMap[nameOrTag] = field.Value.Interface() @@ -125,7 +125,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error } // Merge the custom validation rules with rules in struct tag. - // The custom rules have the highest priority that can overwrite the struct tag rules. + // The custom rules has the most high priority that can overwrite the struct tag rules. for _, field := range tagFields { var ( isMeta bool @@ -144,7 +144,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error // It uses the alias name from validation rule. fieldToAliasNameMap[fieldName] = name } - // It is here extends the params map using alias names. + // It here extends the params map using alias names. // Note that the variable `name` might be alias name or attribute name. if _, ok := inputParamMap[name]; !ok { if !v.useAssocInsteadOfObjectAttributes { @@ -194,7 +194,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error ruleArray = strings.Split(rule, "|") ) for k, ruleKey := range ruleArray { - // If the length of custom messages is less than the length of rules, + // If length of custom messages is lesser than length of rules, // the rest rules use the default error messages. if len(msgArray) <= k { continue @@ -229,7 +229,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error // It checks the struct recursively if its attribute is a struct/struct slice. for _, field := range fieldMap { - // No validation interface implements checks. + // No validation interface implements check. if _, ok := field.Value.Interface().(iNoValidation); ok { continue } @@ -239,7 +239,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error } if field.IsEmbedded() { if err = v.doCheckStruct(ctx, field.Value); err != nil { - // It merges the errors into a single error map. + // It merges the errors into single error map. for k, m := range err.(*validationError).errors { errorMaps[k] = m } @@ -292,7 +292,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error } } } - // It checks each rule and its value in the loop. + // It checks each rule and its value in loop. if validatedError := v.doCheckValue(ctx, doCheckValueInput{ Name: checkRuleItem.Name, Value: value, diff --git a/util/gvalid/gvalid_validator_check_value.go b/util/gvalid/gvalid_validator_check_value.go index 4041d2e5bac..d9981b180e0 100644 --- a/util/gvalid/gvalid_validator_check_value.go +++ b/util/gvalid/gvalid_validator_check_value.go @@ -34,25 +34,26 @@ type iTime interface { } type doCheckValueInput struct { - Name string // Name specifies the name of parameter `value`. - Value interface{} // Value specifies the value for the rules to be validated. - Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. - Messages interface{} // Messages specifies the custom error messages for this rule from parameter input, which is usually the type of map/slice. - DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be the type of map/struct or a nil value. - DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally + Name string // Name specifies the name of parameter `value`. + Value interface{} // Value specifies the value for the rules to be validated. + Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. + Messages interface{} // Messages specifies the custom error messages for this rule from parameters + // input, which is usually type of map/slice. + DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be type of map/struct or a nil value. + DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally } // doCheckSingleValue does the really rules validation for single key-value. func (v *Validator) doCheckValue(ctx context.Context, in doCheckValueInput) Error { - // If there are no validation rules, it does nothing and returns quickly. + // If there's no validation rules, it does nothing and returns quickly. if in.Rule == "" { return nil } // It converts value to string and then does the validation. - var ( - // Do not trim it as the space is also part of the value. - ruleErrorMap = make(map[string]error) - ) + + // Do not trim it as the space is also part of the value. + ruleErrorMap := make(map[string]error) + // Custom error messages handling. var ( msgArray = make([]string, 0) @@ -306,9 +307,7 @@ func (v *Validator) doCheckSingleBuildInRules(ctx context.Context, in doCheckBui if _, err = gtime.StrToTimeFormat(valueStr, in.RulePattern); err == nil { match = true } else { - var ( - msg string - ) + var msg string msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) return match, errors.New(msg) } @@ -385,7 +384,7 @@ func (v *Validator) doCheckSingleBuildInRules(ctx context.Context, in doCheckBui // 3. China Telecom: // 133, 153, 180, 181, 189, 177(4G) // - // 4. Satelite: + // 4. Satellite: // 1349 // // 5. Virtual: diff --git a/util/gvalid/gvalid_validator_message.go b/util/gvalid/gvalid_validator_message.go index ee860deb365..30cab76d8d1 100644 --- a/util/gvalid/gvalid_validator_message.go +++ b/util/gvalid/gvalid_validator_message.go @@ -21,7 +21,7 @@ func (v *Validator) getErrorMessageByRule(ctx context.Context, ruleKey string, c } return content } - // Retrieve default messages according to certain rule. + // Retrieve default message according to certain rule. content = v.i18nManager.GetContent(ctx, ruleMessagePrefixForI18n+ruleKey) if content == "" { content = defaultMessages[ruleKey] diff --git a/util/gvalid/gvalid_validator_rule_luhn.go b/util/gvalid/gvalid_validator_rule_luhn.go index 9d743535d03..701db2ea191 100644 --- a/util/gvalid/gvalid_validator_rule_luhn.go +++ b/util/gvalid/gvalid_validator_rule_luhn.go @@ -15,7 +15,7 @@ func (v *Validator) checkLuHn(value string) bool { parity = nDigits % 2 ) for i := 0; i < nDigits; i++ { - var digit = int(value[i] - 48) + digit := int(value[i] - 48) if i%2 == parity { digit *= 2 if digit > 9 { diff --git a/util/gvalid/gvalid_validator_rule_range.go b/util/gvalid/gvalid_validator_rule_range.go index 752d857ef03..fc8bf3695f0 100644 --- a/util/gvalid/gvalid_validator_rule_range.go +++ b/util/gvalid/gvalid_validator_rule_range.go @@ -59,7 +59,6 @@ func (v *Validator) checkRange(ctx context.Context, value, ruleKey, ruleVal stri msg = v.getErrorMessageByRule(ctx, ruleKey, customMsgMap) msg = strings.Replace(msg, "{max}", strconv.FormatFloat(max, 'f', -1, 64), -1) } - } return msg } diff --git a/util/gvalid/gvalid_validator_rule_resident_id.go b/util/gvalid/gvalid_validator_rule_resident_id.go index df455592417..64848412322 100644 --- a/util/gvalid/gvalid_validator_rule_resident_id.go +++ b/util/gvalid/gvalid_validator_rule_resident_id.go @@ -32,7 +32,7 @@ import ( // 十五位:^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$ // // 总: -// (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$) +// (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$). func (v *Validator) checkResidentId(id string) bool { id = strings.ToUpper(strings.TrimSpace(id)) if len(id) != 18 { From 1b7830091606eea9826d2cdf5a5125fc7df962f2 Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 22:45:36 +0800 Subject: [PATCH 55/70] fix --- os/gstructs/gstructs_field.go | 8 +++++--- text/gstr/gstr_case.go | 4 ++-- text/gstr/gstr_convert.go | 8 +++++--- text/gstr/gstr_similar.go | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/os/gstructs/gstructs_field.go b/os/gstructs/gstructs_field.go index 0583ddfd74c..6e28c07c8c5 100644 --- a/os/gstructs/gstructs_field.go +++ b/os/gstructs/gstructs_field.go @@ -50,7 +50,7 @@ func (f *Field) TagLookup(key string) (value string, ok bool) { return } -// IsEmbedded returns true if the given field is an anonymous field (embedded). +// IsEmbedded returns true if the given field is an anonymous field (embedded) func (f *Field) IsEmbedded() bool { return f.Field.Anonymous } @@ -62,7 +62,9 @@ func (f *Field) TagStr() string { // TagMap returns all the tag of the field along with its value string as map. func (f *Field) TagMap() map[string]string { - data := ParseTag(f.TagStr()) + var ( + data = ParseTag(f.TagStr()) + ) for k, v := range data { data[k] = utils.StripSlashes(gtag.Parse(v)) } @@ -105,7 +107,7 @@ func (f *Field) OriginalKind() reflect.Kind { return kind } -// Fields retrieve and returns the fields of `pointer` as slice. +// Fields retrieves and returns the fields of `pointer` as slice. func Fields(in FieldsInput) ([]Field, error) { var ( ok bool diff --git a/text/gstr/gstr_case.go b/text/gstr/gstr_case.go index d0a6e904591..c07fff72627 100644 --- a/text/gstr/gstr_case.go +++ b/text/gstr/gstr_case.go @@ -83,7 +83,7 @@ func CaseSnakeFirstUpper(word string, underscore ...string) string { return TrimLeft(word, replace) } -// CaseKebab converts a string to kebab-case. +// CaseKebab converts a string to kebab-case func CaseKebab(s string) string { return CaseDelimited(s, '-') } @@ -154,7 +154,7 @@ func addWordBoundariesToNumbers(s string) string { return string(r) } -// Converts a string to CamelCase. +// Converts a string to CamelCase func toCamelInitCase(s string, initCase bool) string { s = addWordBoundariesToNumbers(s) s = strings.Trim(s, " ") diff --git a/text/gstr/gstr_convert.go b/text/gstr/gstr_convert.go index 13e9760d6d9..badfda24120 100644 --- a/text/gstr/gstr_convert.go +++ b/text/gstr/gstr_convert.go @@ -28,12 +28,14 @@ func Ord(char string) int { return int(char[0]) } -// octReg is the regular expression object for checks octal string. -var octReg = regexp.MustCompile(`\\[0-7]{3}`) +var ( + // octReg is the regular expression object for checks octal string. + octReg = regexp.MustCompile(`\\[0-7]{3}`) +) // OctStr converts string container octal string to its original string, // for example, to Chinese string. -// Eg: `\346\200\241` -> 怡. +// Eg: `\346\200\241` -> 怡 func OctStr(str string) string { return octReg.ReplaceAllStringFunc( str, diff --git a/text/gstr/gstr_similar.go b/text/gstr/gstr_similar.go index 55d729726fd..7c19618fb6c 100644 --- a/text/gstr/gstr_similar.go +++ b/text/gstr/gstr_similar.go @@ -12,7 +12,7 @@ package gstr // costDel: Defines the cost of deletion. // See http://php.net/manual/en/function.levenshtein.php. func Levenshtein(str1, str2 string, costIns, costRep, costDel int) int { - maxLen := 255 + var maxLen = 255 l1 := len(str1) l2 := len(str2) if l1 == 0 { From 53871b657f449648fdb5ff262979f11038cb1846 Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 22:52:53 +0800 Subject: [PATCH 56/70] fix --- text/gstr/gstr_parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/gstr/gstr_parse.go b/text/gstr/gstr_parse.go index 632a0e242fc..4a95780a32c 100644 --- a/text/gstr/gstr_parse.go +++ b/text/gstr/gstr_parse.go @@ -23,7 +23,7 @@ import ( // v[a][]=m&v[a][]=n -> map[v:map[a:[m n]]] // v[][]=m&v[][]=n -> map[v:[map[]]] // Currently does not support nested slice. // v=m&v[a]=n -> error -// a .[[b=c -> map[a___[b:c]. +// a .[[b=c -> map[a___[b:c] // func Parse(s string) (result map[string]interface{}, err error) { if s == "" { From 9985103bb39d8c8924bc8013e3cdd2dc02e99dae Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 23:02:59 +0800 Subject: [PATCH 57/70] up --- util/gvalid/gvalid.go | 2 +- util/gvalid/gvalid_custom_rule.go | 10 ++++++---- util/gvalid/gvalid_error.go | 2 +- util/gvalid/gvalid_validator_check_struct.go | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/util/gvalid/gvalid.go b/util/gvalid/gvalid.go index 122e560ac65..80373104fd9 100644 --- a/util/gvalid/gvalid.go +++ b/util/gvalid/gvalid.go @@ -205,7 +205,7 @@ var ( ) // ParseTagValue parses one sequence tag to field, rule and error message. -// The sequence tag is like: [alias@]rule[...#msg...]. +// The sequence tag is like: [alias@]rule[...#msg...] func ParseTagValue(tag string) (field, rule, msg string) { // Complete sequence tag. // Example: name@required|length:2,20|password3|same:password1#||密码强度不足|两次密码不一致 diff --git a/util/gvalid/gvalid_custom_rule.go b/util/gvalid/gvalid_custom_rule.go index 315d2e36b55..701c67e4f9c 100644 --- a/util/gvalid/gvalid_custom_rule.go +++ b/util/gvalid/gvalid_custom_rule.go @@ -35,11 +35,13 @@ type RuleFuncInput struct { Data *gvar.Var } -// customRuleFuncMap stores the custom rule functions. -// map[Rule]RuleFunc. -var customRuleFuncMap = make(map[string]RuleFunc) +var ( + // customRuleFuncMap stores the custom rule functions. + // map[Rule]RuleFunc. + customRuleFuncMap = make(map[string]RuleFunc) +) -// RegisterRule registers custom validation rules and function for package. +// RegisterRule registers custom validation rule and function for package. func RegisterRule(rule string, f RuleFunc) { if customRuleFuncMap[rule] != nil { intlog.PrintFunc(context.TODO(), func() string { diff --git a/util/gvalid/gvalid_error.go b/util/gvalid/gvalid_error.go index 4d81a56c44d..cd6593da747 100644 --- a/util/gvalid/gvalid_error.go +++ b/util/gvalid/gvalid_error.go @@ -54,7 +54,7 @@ func newValidationError(code gcode.Code, rules []fieldRule, fieldRuleErrorMap ma fieldRuleErrorMap[field] = ruleErrorMap } // Filter repeated sequence rules. - ruleNameSet := gset.NewStrSet() + var ruleNameSet = gset.NewStrSet() for i := 0; i < len(rules); { if !ruleNameSet.AddIfNotExist(rules[i].Name) { // Delete repeated rule. diff --git a/util/gvalid/gvalid_validator_check_struct.go b/util/gvalid/gvalid_validator_check_struct.go index 8482ba19e00..50601deba74 100644 --- a/util/gvalid/gvalid_validator_check_struct.go +++ b/util/gvalid/gvalid_validator_check_struct.go @@ -22,7 +22,7 @@ import ( func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error { var ( errorMaps = make(map[string]map[string]error) // Returning error. - fieldToAliasNameMap = make(map[string]string) // Field names to alias name maps. + fieldToAliasNameMap = make(map[string]string) // Field names to alias name map. resultSequenceRules = make([]fieldRule, 0) isEmptyData = empty.IsEmpty(v.data) isEmptyAssoc = empty.IsEmpty(v.assoc) @@ -51,7 +51,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error checkRules = make([]fieldRule, 0) nameToRuleMap = make(map[string]string) // just for internally searching index purpose. customMessage = make(CustomMsg) // Custom rule error message map. - checkValueData = v.assoc // Ready to be validated data, which can be type of. + checkValueData = v.assoc // Ready to be validated data, which can be type of ) if checkValueData == nil { checkValueData = object From 405c52f938bb625e75110edfa95a491103b9ed27 Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 23:15:45 +0800 Subject: [PATCH 58/70] up --- contrib/registry/polaris/.gitignore | 11 - contrib/registry/polaris/doc.go | 8 - .../{registry.go => polaris_registry.go} | 1 + ...istry_test.go => polaris_registry_test.go} | 0 example/.gitignore | 100 -- util/gvalid/gvalid_custom_rule.go | 2 +- util/gvalid/gvalid_validator.go | 2 +- util/gvalid/gvalid_validator_check_struct.go | 2 +- util/gvalid/gvalid_validator_check_value.go | 1154 +++++++++-------- util/gvalid/gvalid_validator_rule_luhn.go | 2 +- .../gvalid_validator_rule_resident_id.go | 2 +- 11 files changed, 584 insertions(+), 700 deletions(-) delete mode 100644 contrib/registry/polaris/.gitignore delete mode 100644 contrib/registry/polaris/doc.go rename contrib/registry/polaris/{registry.go => polaris_registry.go} (99%) rename contrib/registry/polaris/{registry_test.go => polaris_registry_test.go} (100%) delete mode 100644 example/.gitignore diff --git a/contrib/registry/polaris/.gitignore b/contrib/registry/polaris/.gitignore deleted file mode 100644 index c13ec1d86b8..00000000000 --- a/contrib/registry/polaris/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -### Example user template template -### Example user template - -# IntelliJ project files -.idea -*.iml -out -gen - -*.log -*.json \ No newline at end of file diff --git a/contrib/registry/polaris/doc.go b/contrib/registry/polaris/doc.go deleted file mode 100644 index 9ffc871b00c..00000000000 --- a/contrib/registry/polaris/doc.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -// Package polaris implements service Registry and Discovery using polaris. -package polaris diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/polaris_registry.go similarity index 99% rename from contrib/registry/polaris/registry.go rename to contrib/registry/polaris/polaris_registry.go index f34313d4b15..e6fe66a50cf 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/polaris_registry.go @@ -4,6 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. +// Package polaris implements service Registry and Discovery using polaris. package polaris import ( diff --git a/contrib/registry/polaris/registry_test.go b/contrib/registry/polaris/polaris_registry_test.go similarity index 100% rename from contrib/registry/polaris/registry_test.go rename to contrib/registry/polaris/polaris_registry_test.go diff --git a/example/.gitignore b/example/.gitignore deleted file mode 100644 index 7a707e97e3b..00000000000 --- a/example/.gitignore +++ /dev/null @@ -1,100 +0,0 @@ -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### Example user template template -### Example user template - -# IntelliJ project files -.idea -*.iml -out -gen -### Go template -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ - -*.log -*.json \ No newline at end of file diff --git a/util/gvalid/gvalid_custom_rule.go b/util/gvalid/gvalid_custom_rule.go index 701c67e4f9c..2521eb4bff7 100644 --- a/util/gvalid/gvalid_custom_rule.go +++ b/util/gvalid/gvalid_custom_rule.go @@ -37,7 +37,7 @@ type RuleFuncInput struct { var ( // customRuleFuncMap stores the custom rule functions. - // map[Rule]RuleFunc. + // map[Rule]RuleFunc customRuleFuncMap = make(map[string]RuleFunc) ) diff --git a/util/gvalid/gvalid_validator.go b/util/gvalid/gvalid_validator.go index 99bc5ff3d30..944774f3cf4 100644 --- a/util/gvalid/gvalid_validator.go +++ b/util/gvalid/gvalid_validator.go @@ -125,7 +125,7 @@ func (v *Validator) Data(data interface{}) *Validator { // Assoc is a chaining operation function, which sets associated validation data for current operation. // The optional parameter `assoc` is usually type of map, which specifies the parameter map used in union validation. -// Calling this function with `assoc` also sets `useAssocInsteadOfObjectAttributes` true. +// Calling this function with `assoc` also sets `useAssocInsteadOfObjectAttributes` true func (v *Validator) Assoc(assoc interface{}) *Validator { if assoc == nil { return v diff --git a/util/gvalid/gvalid_validator_check_struct.go b/util/gvalid/gvalid_validator_check_struct.go index 50601deba74..42244db40a2 100644 --- a/util/gvalid/gvalid_validator_check_struct.go +++ b/util/gvalid/gvalid_validator_check_struct.go @@ -51,7 +51,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error checkRules = make([]fieldRule, 0) nameToRuleMap = make(map[string]string) // just for internally searching index purpose. customMessage = make(CustomMsg) // Custom rule error message map. - checkValueData = v.assoc // Ready to be validated data, which can be type of + checkValueData = v.assoc // Ready to be validated data, which can be type of . ) if checkValueData == nil { checkValueData = object diff --git a/util/gvalid/gvalid_validator_check_value.go b/util/gvalid/gvalid_validator_check_value.go index d9981b180e0..9e5cf1c000d 100644 --- a/util/gvalid/gvalid_validator_check_value.go +++ b/util/gvalid/gvalid_validator_check_value.go @@ -7,602 +7,604 @@ package gvalid import ( - "context" - "errors" - "reflect" - "strconv" - "strings" - "time" - - "github.com/gogf/gf/v2/container/gvar" - "github.com/gogf/gf/v2/encoding/gjson" - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/internal/json" - "github.com/gogf/gf/v2/net/gipv4" - "github.com/gogf/gf/v2/net/gipv6" - "github.com/gogf/gf/v2/os/gtime" - "github.com/gogf/gf/v2/text/gregex" - "github.com/gogf/gf/v2/text/gstr" - "github.com/gogf/gf/v2/util/gconv" - "github.com/gogf/gf/v2/util/gutil" + "context" + "errors" + "reflect" + "strconv" + "strings" + "time" + + "github.com/gogf/gf/v2/container/gvar" + "github.com/gogf/gf/v2/encoding/gjson" + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/internal/json" + "github.com/gogf/gf/v2/net/gipv4" + "github.com/gogf/gf/v2/net/gipv6" + "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/text/gregex" + "github.com/gogf/gf/v2/text/gstr" + "github.com/gogf/gf/v2/util/gconv" + "github.com/gogf/gf/v2/util/gutil" ) type iTime interface { - Date() (year int, month time.Month, day int) - IsZero() bool + Date() (year int, month time.Month, day int) + IsZero() bool } type doCheckValueInput struct { - Name string // Name specifies the name of parameter `value`. - Value interface{} // Value specifies the value for the rules to be validated. - Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. - Messages interface{} // Messages specifies the custom error messages for this rule from parameters - // input, which is usually type of map/slice. - DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be type of map/struct or a nil value. - DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally + Name string // Name specifies the name of parameter `value`. + Value interface{} // Value specifies the value for the rules to be validated. + Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. + Messages interface{} // Messages specifies the custom error messages for this rule from parameters + // input, which is usually type of map/slice. + DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be type of map/struct or a nil value. + DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally } // doCheckSingleValue does the really rules validation for single key-value. func (v *Validator) doCheckValue(ctx context.Context, in doCheckValueInput) Error { - // If there's no validation rules, it does nothing and returns quickly. - if in.Rule == "" { - return nil - } - // It converts value to string and then does the validation. - - // Do not trim it as the space is also part of the value. - ruleErrorMap := make(map[string]error) - - // Custom error messages handling. - var ( - msgArray = make([]string, 0) - customMsgMap = make(map[string]string) - ) - switch messages := in.Messages.(type) { - case string: - msgArray = strings.Split(messages, "|") - - default: - for k, message := range gconv.Map(in.Messages) { - customMsgMap[k] = gconv.String(message) - } - } - // Handle the char '|' in the rule, - // which makes this rule separated into multiple rules. - ruleItems := strings.Split(strings.TrimSpace(in.Rule), "|") - for i := 0; ; { - array := strings.Split(ruleItems[i], ":") - _, ok := allSupportedRules[array[0]] - if !ok && v.getRuleFunc(array[0]) == nil { - if i > 0 && ruleItems[i-1][:5] == "regex" { - ruleItems[i-1] += "|" + ruleItems[i] - ruleItems = append(ruleItems[:i], ruleItems[i+1:]...) - } else { - return newValidationErrorByStr( - internalRulesErrRuleName, - errors.New(internalRulesErrRuleName+": "+ruleItems[i]), - ) - } - } else { - i++ - } - if i == len(ruleItems) { - break - } - } - var ( - hasBailRule = v.bail - hasCaseInsensitive = v.caseInsensitive - ) - for index := 0; index < len(ruleItems); { - var ( - err error - match = false // whether this rule is matched(has no error) - results = ruleRegex.FindStringSubmatch(ruleItems[index]) // split single rule. - ruleKey = gstr.Trim(results[1]) // rule key like "max" in rule "max: 6" - rulePattern = gstr.Trim(results[2]) // rule pattern is like "6" in rule:"max:6" - customRuleFunc RuleFunc - ) - - if !hasBailRule && ruleKey == ruleNameBail { - hasBailRule = true - } - - if !hasCaseInsensitive && ruleKey == ruleNameCi { - hasCaseInsensitive = true - } - - // Ignore logic executing for marked rules. - if markedRuleMap[ruleKey] { - index++ - continue - } - - if len(msgArray) > index { - customMsgMap[ruleKey] = strings.TrimSpace(msgArray[index]) - } - - // =========================================================================================== - // Custom rule handling - // =========================================================================================== - // 1. It firstly checks and uses the custom registered rules functions in the current Validator. - // 2. It secondly checks and uses the globally registered rules functions. - // 3. It finally checks and uses the build-in rules functions. - customRuleFunc = v.getRuleFunc(ruleKey) - if customRuleFunc != nil { - // It checks custom validation rules with most priority. - message := v.getErrorMessageByRule(ctx, ruleKey, customMsgMap) - if err = customRuleFunc(ctx, RuleFuncInput{ - Rule: ruleItems[index], - Message: message, - Value: gvar.New(in.Value), - Data: gvar.New(in.DataRaw), - }); err != nil { - match = false - // The error should have stack info to indicate the error position. - if !gerror.HasStack(err) { - err = gerror.NewCodeSkip(gcode.CodeValidationFailed, 1, err.Error()) - } - // The error should have error code that is `gcode.CodeValidationFailed`. - if gerror.Code(err) == gcode.CodeNil { - if e, ok := err.(*gerror.Error); ok { - e.SetCode(gcode.CodeValidationFailed) - } - } - ruleErrorMap[ruleKey] = err - } else { - match = true - } - } else { - // It checks build-in validation rules if there's no custom rule. - match, err = v.doCheckSingleBuildInRules( - ctx, - doCheckBuildInRulesInput{ - Index: index, - Value: in.Value, - RuleKey: ruleKey, - RulePattern: rulePattern, - RuleItems: ruleItems, - DataMap: in.DataMap, - CustomMsgMap: customMsgMap, - CaseInsensitive: hasCaseInsensitive, - }, - ) - if !match && err != nil { - ruleErrorMap[ruleKey] = err - } - } - - // Error message handling. - if !match { - // It does nothing if the error message for this rule - // is already set in previous validation. - if _, ok := ruleErrorMap[ruleKey]; !ok { - ruleErrorMap[ruleKey] = errors.New(v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)) - } - - // Error variable replacement for error message. - if err = ruleErrorMap[ruleKey]; !gerror.HasStack(err) { - var s string - s = gstr.ReplaceByMap(err.Error(), map[string]string{ - "{value}": gconv.String(in.Value), - "{pattern}": rulePattern, - "{attribute}": in.Name, - }) - s, _ = gregex.ReplaceString(`\s{2,}`, ` `, s) - ruleErrorMap[ruleKey] = errors.New(s) - } - - // If it is with error and there's bail rule, - // it then does not continue validating for left rules. - if hasBailRule { - break - } - } - index++ - } - if len(ruleErrorMap) > 0 { - return newValidationError( - gcode.CodeValidationFailed, - []fieldRule{{Name: in.Name, Rule: in.Rule}}, - map[string]map[string]error{ - in.Name: ruleErrorMap, - }, - ) - } - return nil + // If there's no validation rules, it does nothing and returns quickly. + if in.Rule == "" { + return nil + } + // It converts value to string and then does the validation. + var ( + // Do not trim it as the space is also part of the value. + ruleErrorMap = make(map[string]error) + ) + // Custom error messages handling. + var ( + msgArray = make([]string, 0) + customMsgMap = make(map[string]string) + ) + switch messages := in.Messages.(type) { + case string: + msgArray = strings.Split(messages, "|") + + default: + for k, message := range gconv.Map(in.Messages) { + customMsgMap[k] = gconv.String(message) + } + } + // Handle the char '|' in the rule, + // which makes this rule separated into multiple rules. + ruleItems := strings.Split(strings.TrimSpace(in.Rule), "|") + for i := 0; ; { + array := strings.Split(ruleItems[i], ":") + _, ok := allSupportedRules[array[0]] + if !ok && v.getRuleFunc(array[0]) == nil { + if i > 0 && ruleItems[i-1][:5] == "regex" { + ruleItems[i-1] += "|" + ruleItems[i] + ruleItems = append(ruleItems[:i], ruleItems[i+1:]...) + } else { + return newValidationErrorByStr( + internalRulesErrRuleName, + errors.New(internalRulesErrRuleName+": "+ruleItems[i]), + ) + } + } else { + i++ + } + if i == len(ruleItems) { + break + } + } + var ( + hasBailRule = v.bail + hasCaseInsensitive = v.caseInsensitive + ) + for index := 0; index < len(ruleItems); { + var ( + err error + match = false // whether this rule is matched(has no error) + results = ruleRegex.FindStringSubmatch(ruleItems[index]) // split single rule. + ruleKey = gstr.Trim(results[1]) // rule key like "max" in rule "max: 6" + rulePattern = gstr.Trim(results[2]) // rule pattern is like "6" in rule:"max:6" + customRuleFunc RuleFunc + ) + + if !hasBailRule && ruleKey == ruleNameBail { + hasBailRule = true + } + + if !hasCaseInsensitive && ruleKey == ruleNameCi { + hasCaseInsensitive = true + } + + // Ignore logic executing for marked rules. + if markedRuleMap[ruleKey] { + index++ + continue + } + + if len(msgArray) > index { + customMsgMap[ruleKey] = strings.TrimSpace(msgArray[index]) + } + + // =========================================================================================== + // Custom rule handling + // =========================================================================================== + // 1. It firstly checks and uses the custom registered rules functions in the current Validator. + // 2. It secondly checks and uses the globally registered rules functions. + // 3. It finally checks and uses the build-in rules functions. + customRuleFunc = v.getRuleFunc(ruleKey) + if customRuleFunc != nil { + // It checks custom validation rules with most priority. + message := v.getErrorMessageByRule(ctx, ruleKey, customMsgMap) + if err = customRuleFunc(ctx, RuleFuncInput{ + Rule: ruleItems[index], + Message: message, + Value: gvar.New(in.Value), + Data: gvar.New(in.DataRaw), + }); err != nil { + match = false + // The error should have stack info to indicate the error position. + if !gerror.HasStack(err) { + err = gerror.NewCodeSkip(gcode.CodeValidationFailed, 1, err.Error()) + } + // The error should have error code that is `gcode.CodeValidationFailed`. + if gerror.Code(err) == gcode.CodeNil { + if e, ok := err.(*gerror.Error); ok { + e.SetCode(gcode.CodeValidationFailed) + } + } + ruleErrorMap[ruleKey] = err + } else { + match = true + } + } else { + // It checks build-in validation rules if there's no custom rule. + match, err = v.doCheckSingleBuildInRules( + ctx, + doCheckBuildInRulesInput{ + Index: index, + Value: in.Value, + RuleKey: ruleKey, + RulePattern: rulePattern, + RuleItems: ruleItems, + DataMap: in.DataMap, + CustomMsgMap: customMsgMap, + CaseInsensitive: hasCaseInsensitive, + }, + ) + if !match && err != nil { + ruleErrorMap[ruleKey] = err + } + } + + // Error message handling. + if !match { + // It does nothing if the error message for this rule + // is already set in previous validation. + if _, ok := ruleErrorMap[ruleKey]; !ok { + ruleErrorMap[ruleKey] = errors.New(v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)) + } + + // Error variable replacement for error message. + if err = ruleErrorMap[ruleKey]; !gerror.HasStack(err) { + var s string + s = gstr.ReplaceByMap(err.Error(), map[string]string{ + "{value}": gconv.String(in.Value), + "{pattern}": rulePattern, + "{attribute}": in.Name, + }) + s, _ = gregex.ReplaceString(`\s{2,}`, ` `, s) + ruleErrorMap[ruleKey] = errors.New(s) + } + + // If it is with error and there's bail rule, + // it then does not continue validating for left rules. + if hasBailRule { + break + } + } + index++ + } + if len(ruleErrorMap) > 0 { + return newValidationError( + gcode.CodeValidationFailed, + []fieldRule{{Name: in.Name, Rule: in.Rule}}, + map[string]map[string]error{ + in.Name: ruleErrorMap, + }, + ) + } + return nil } type doCheckBuildInRulesInput struct { - Index int // Index of RuleKey in RuleItems. - Value interface{} // Value to be validated. - RuleKey string // RuleKey is like the "max" in rule "max: 6" - RulePattern string // RulePattern is like "6" in rule:"max:6" - RuleItems []string // RuleItems are all the rules that should be validated on single field, like: []string{"required", "min:1"} - DataMap map[string]interface{} // Parameter map. - CustomMsgMap map[string]string // Custom error message map. - CaseInsensitive bool // Case-Insensitive comparison. + Index int // Index of RuleKey in RuleItems. + Value interface{} // Value to be validated. + RuleKey string // RuleKey is like the "max" in rule "max: 6" + RulePattern string // RulePattern is like "6" in rule:"max:6" + RuleItems []string // RuleItems are all the rules that should be validated on single field, like: []string{"required", "min:1"} + DataMap map[string]interface{} // Parameter map. + CustomMsgMap map[string]string // Custom error message map. + CaseInsensitive bool // Case-Insensitive comparison. } func (v *Validator) doCheckSingleBuildInRules(ctx context.Context, in doCheckBuildInRulesInput) (match bool, err error) { - valueStr := gconv.String(in.Value) - switch in.RuleKey { - // Required rules. - case - "required", - "required-if", - "required-unless", - "required-with", - "required-with-all", - "required-without", - "required-without-all": - match = v.checkRequired(checkRequiredInput{ - Value: in.Value, - RuleKey: in.RuleKey, - RulePattern: in.RulePattern, - DataMap: in.DataMap, - CaseInsensitive: in.CaseInsensitive, - }) - - // Length rules. - // It also supports length of unicode string. - case - "length", - "min-length", - "max-length", - "size": - if msg := v.checkLength(ctx, valueStr, in.RuleKey, in.RulePattern, in.CustomMsgMap); msg != "" { - return match, errors.New(msg) - } else { - match = true - } - - // Range rules. - case - "min", - "max", - "between": - if msg := v.checkRange(ctx, valueStr, in.RuleKey, in.RulePattern, in.CustomMsgMap); msg != "" { - return match, errors.New(msg) - } else { - match = true - } - - // Custom regular expression. - case "regex": - // It here should check the rule as there might be special char '|' in it. - for i := in.Index + 1; i < len(in.RuleItems); i++ { - if !gregex.IsMatchString(singleRulePattern, in.RuleItems[i]) { - in.RulePattern += "|" + in.RuleItems[i] - in.Index++ - } - } - match = gregex.IsMatchString(in.RulePattern, valueStr) - - // Date rules. - case "date": - // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. - if value, ok := in.Value.(iTime); ok { - return !value.IsZero(), nil - } - match = gregex.IsMatchString(`\d{4}[\.\-\_/]{0,1}\d{2}[\.\-\_/]{0,1}\d{2}`, valueStr) - - // Datetime rule. - case "datetime": - // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. - if value, ok := in.Value.(iTime); ok { - return !value.IsZero(), nil - } - if _, err = gtime.StrToTimeFormat(valueStr, `Y-m-d H:i:s`); err == nil { - match = true - } - - // Date rule with specified format. - case "date-format": - // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. - if value, ok := in.Value.(iTime); ok { - return !value.IsZero(), nil - } - if _, err = gtime.StrToTimeFormat(valueStr, in.RulePattern); err == nil { - match = true - } else { - var msg string - msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) - return match, errors.New(msg) - } - - // Values of two fields should be equal as string. - case "same": - _, foundValue := gutil.MapPossibleItemByKey(in.DataMap, in.RulePattern) - if foundValue != nil { - if in.CaseInsensitive { - match = strings.EqualFold(valueStr, gconv.String(foundValue)) - } else { - match = strings.Compare(valueStr, gconv.String(foundValue)) == 0 - } - } - if !match { - var msg string - msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) - return match, errors.New(msg) - } - - // Values of two fields should not be equal as string. - case "different": - match = true - _, foundValue := gutil.MapPossibleItemByKey(in.DataMap, in.RulePattern) - if foundValue != nil { - if in.CaseInsensitive { - match = !strings.EqualFold(valueStr, gconv.String(foundValue)) - } else { - match = strings.Compare(valueStr, gconv.String(foundValue)) != 0 - } - } - if !match { - var msg string - msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) - return match, errors.New(msg) - } - - // Field value should be in range of. - case "in": - for _, value := range gstr.SplitAndTrim(in.RulePattern, ",") { - if in.CaseInsensitive { - match = strings.EqualFold(valueStr, strings.TrimSpace(value)) - } else { - match = strings.Compare(valueStr, strings.TrimSpace(value)) == 0 - } - if match { - break - } - } - - // Field value should not be in range of. - case "not-in": - match = true - for _, value := range gstr.SplitAndTrim(in.RulePattern, ",") { - if in.CaseInsensitive { - match = !strings.EqualFold(valueStr, strings.TrimSpace(value)) - } else { - match = strings.Compare(valueStr, strings.TrimSpace(value)) != 0 - } - if !match { - break - } - } - - // Phone format validation. - // 1. China Mobile: - // 134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, - // 178(4G), 147(Net); - // 172 - // - // 2. China Unicom: - // 130, 131, 132, 155, 156, 185, 186 ,176(4G), 145(Net), 175 - // - // 3. China Telecom: - // 133, 153, 180, 181, 189, 177(4G) - // - // 4. Satellite: - // 1349 - // - // 5. Virtual: - // 170, 173 - // - // 6. 2018: - // 16x, 19x - case "phone": - match = gregex.IsMatchString(`^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^16[\d]{9}$|^17[0,2,3,5,6,7,8]{1}\d{8}$|^18[\d]{9}$|^19[\d]{9}$`, valueStr) - - // Loose mobile phone number verification(宽松的手机号验证) - // As long as the 11 digit numbers beginning with - // 13, 14, 15, 16, 17, 18, 19 can pass the verification (只要满足 13、14、15、16、17、18、19开头的11位数字都可以通过验证) - case "phone-loose": - match = gregex.IsMatchString(`^1(3|4|5|6|7|8|9)\d{9}$`, valueStr) - - // Telephone number: - // "XXXX-XXXXXXX" - // "XXXX-XXXXXXXX" - // "XXX-XXXXXXX" - // "XXX-XXXXXXXX" - // "XXXXXXX" - // "XXXXXXXX" - case "telephone": - match = gregex.IsMatchString(`^((\d{3,4})|\d{3,4}-)?\d{7,8}$`, valueStr) - - // QQ number: from 10000. - case "qq": - match = gregex.IsMatchString(`^[1-9][0-9]{4,}$`, valueStr) - - // Postcode number. - case "postcode": - match = gregex.IsMatchString(`^\d{6}$`, valueStr) - - // China resident id number. - // - // xxxxxx yyyy MM dd 375 0 十八位 - // xxxxxx yy MM dd 75 0 十五位 - // - // 地区: [1-9]\d{5} - // 年的前两位:(18|19|([23]\d)) 1800-2399 - // 年的后两位:\d{2} - // 月份: ((0[1-9])|(10|11|12)) - // 天数: (([0-2][1-9])|10|20|30|31) 闰年不能禁止29+ - // - // 三位顺序码:\d{3} - // 两位顺序码:\d{2} - // 校验码: [0-9Xx] - // - // 十八位:^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$ - // 十五位:^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$ - // - // 总: - // (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$) - case "resident-id": - match = v.checkResidentId(valueStr) - - // Bank card number using LUHN algorithm. - case "bank-card": - match = v.checkLuHn(valueStr) - - // Universal passport format rule: - // Starting with letter, containing only numbers or underscores, length between 6 and 18. - case "passport": - match = gregex.IsMatchString(`^[a-zA-Z]{1}\w{5,17}$`, valueStr) - - // Universal password format rule1: - // Containing any visible chars, length between 6 and 18. - case "password": - match = gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) - - // Universal password format rule2: - // Must meet password rule1, must contain lower and upper letters and numbers. - case "password2": - if gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) && - gregex.IsMatchString(`[a-z]+`, valueStr) && - gregex.IsMatchString(`[A-Z]+`, valueStr) && - gregex.IsMatchString(`\d+`, valueStr) { - match = true - } - - // Universal password format rule3: - // Must meet password rule1, must contain lower and upper letters, numbers and special chars. - case "password3": - if gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) && - gregex.IsMatchString(`[a-z]+`, valueStr) && - gregex.IsMatchString(`[A-Z]+`, valueStr) && - gregex.IsMatchString(`\d+`, valueStr) && - gregex.IsMatchString(`[^a-zA-Z0-9]+`, valueStr) { - match = true - } - - // Json. - case "json": - if json.Valid([]byte(valueStr)) { - match = true - } - - // Integer. - case "integer": - if _, err = strconv.Atoi(valueStr); err == nil { - match = true - } - - // Float. - case "float": - if _, err = strconv.ParseFloat(valueStr, 10); err == nil { - match = true - } - - // Boolean(1,true,on,yes:true | 0,false,off,no,"":false). - case "boolean": - match = false - if _, ok := boolMap[strings.ToLower(valueStr)]; ok { - match = true - } - - // Email. - case "email": - match = gregex.IsMatchString(`^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+)+$`, valueStr) - - // URL - case "url": - match = gregex.IsMatchString(`(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]`, valueStr) - - // Domain - case "domain": - match = gregex.IsMatchString(`^([0-9a-zA-Z][0-9a-zA-Z\-]{0,62}\.)+([a-zA-Z]{0,62})$`, valueStr) - - // IP(IPv4/IPv6). - case "ip": - match = gipv4.Validate(valueStr) || gipv6.Validate(valueStr) - - // IPv4. - case "ipv4": - match = gipv4.Validate(valueStr) - - // IPv6. - case "ipv6": - match = gipv6.Validate(valueStr) - - // MAC. - case "mac": - match = gregex.IsMatchString(`^([0-9A-Fa-f]{2}[\-:]){5}[0-9A-Fa-f]{2}$`, valueStr) - - default: - return match, errors.New("Invalid rule name: " + in.RuleKey) - } - return match, nil + valueStr := gconv.String(in.Value) + switch in.RuleKey { + // Required rules. + case + "required", + "required-if", + "required-unless", + "required-with", + "required-with-all", + "required-without", + "required-without-all": + match = v.checkRequired(checkRequiredInput{ + Value: in.Value, + RuleKey: in.RuleKey, + RulePattern: in.RulePattern, + DataMap: in.DataMap, + CaseInsensitive: in.CaseInsensitive, + }) + + // Length rules. + // It also supports length of unicode string. + case + "length", + "min-length", + "max-length", + "size": + if msg := v.checkLength(ctx, valueStr, in.RuleKey, in.RulePattern, in.CustomMsgMap); msg != "" { + return match, errors.New(msg) + } else { + match = true + } + + // Range rules. + case + "min", + "max", + "between": + if msg := v.checkRange(ctx, valueStr, in.RuleKey, in.RulePattern, in.CustomMsgMap); msg != "" { + return match, errors.New(msg) + } else { + match = true + } + + // Custom regular expression. + case "regex": + // It here should check the rule as there might be special char '|' in it. + for i := in.Index + 1; i < len(in.RuleItems); i++ { + if !gregex.IsMatchString(singleRulePattern, in.RuleItems[i]) { + in.RulePattern += "|" + in.RuleItems[i] + in.Index++ + } + } + match = gregex.IsMatchString(in.RulePattern, valueStr) + + // Date rules. + case "date": + // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. + if value, ok := in.Value.(iTime); ok { + return !value.IsZero(), nil + } + match = gregex.IsMatchString(`\d{4}[\.\-\_/]{0,1}\d{2}[\.\-\_/]{0,1}\d{2}`, valueStr) + + // Datetime rule. + case "datetime": + // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. + if value, ok := in.Value.(iTime); ok { + return !value.IsZero(), nil + } + if _, err = gtime.StrToTimeFormat(valueStr, `Y-m-d H:i:s`); err == nil { + match = true + } + + // Date rule with specified format. + case "date-format": + // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. + if value, ok := in.Value.(iTime); ok { + return !value.IsZero(), nil + } + if _, err = gtime.StrToTimeFormat(valueStr, in.RulePattern); err == nil { + match = true + } else { + var ( + msg string + ) + msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) + return match, errors.New(msg) + } + + // Values of two fields should be equal as string. + case "same": + _, foundValue := gutil.MapPossibleItemByKey(in.DataMap, in.RulePattern) + if foundValue != nil { + if in.CaseInsensitive { + match = strings.EqualFold(valueStr, gconv.String(foundValue)) + } else { + match = strings.Compare(valueStr, gconv.String(foundValue)) == 0 + } + } + if !match { + var msg string + msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) + return match, errors.New(msg) + } + + // Values of two fields should not be equal as string. + case "different": + match = true + _, foundValue := gutil.MapPossibleItemByKey(in.DataMap, in.RulePattern) + if foundValue != nil { + if in.CaseInsensitive { + match = !strings.EqualFold(valueStr, gconv.String(foundValue)) + } else { + match = strings.Compare(valueStr, gconv.String(foundValue)) != 0 + } + } + if !match { + var msg string + msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) + return match, errors.New(msg) + } + + // Field value should be in range of. + case "in": + for _, value := range gstr.SplitAndTrim(in.RulePattern, ",") { + if in.CaseInsensitive { + match = strings.EqualFold(valueStr, strings.TrimSpace(value)) + } else { + match = strings.Compare(valueStr, strings.TrimSpace(value)) == 0 + } + if match { + break + } + } + + // Field value should not be in range of. + case "not-in": + match = true + for _, value := range gstr.SplitAndTrim(in.RulePattern, ",") { + if in.CaseInsensitive { + match = !strings.EqualFold(valueStr, strings.TrimSpace(value)) + } else { + match = strings.Compare(valueStr, strings.TrimSpace(value)) != 0 + } + if !match { + break + } + } + + // Phone format validation. + // 1. China Mobile: + // 134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, + // 178(4G), 147(Net); + // 172 + // + // 2. China Unicom: + // 130, 131, 132, 155, 156, 185, 186 ,176(4G), 145(Net), 175 + // + // 3. China Telecom: + // 133, 153, 180, 181, 189, 177(4G) + // + // 4. Satelite: + // 1349 + // + // 5. Virtual: + // 170, 173 + // + // 6. 2018: + // 16x, 19x + case "phone": + match = gregex.IsMatchString(`^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^16[\d]{9}$|^17[0,2,3,5,6,7,8]{1}\d{8}$|^18[\d]{9}$|^19[\d]{9}$`, valueStr) + + // Loose mobile phone number verification(宽松的手机号验证) + // As long as the 11 digit numbers beginning with + // 13, 14, 15, 16, 17, 18, 19 can pass the verification (只要满足 13、14、15、16、17、18、19开头的11位数字都可以通过验证) + case "phone-loose": + match = gregex.IsMatchString(`^1(3|4|5|6|7|8|9)\d{9}$`, valueStr) + + // Telephone number: + // "XXXX-XXXXXXX" + // "XXXX-XXXXXXXX" + // "XXX-XXXXXXX" + // "XXX-XXXXXXXX" + // "XXXXXXX" + // "XXXXXXXX" + case "telephone": + match = gregex.IsMatchString(`^((\d{3,4})|\d{3,4}-)?\d{7,8}$`, valueStr) + + // QQ number: from 10000. + case "qq": + match = gregex.IsMatchString(`^[1-9][0-9]{4,}$`, valueStr) + + // Postcode number. + case "postcode": + match = gregex.IsMatchString(`^\d{6}$`, valueStr) + + // China resident id number. + // + // xxxxxx yyyy MM dd 375 0 十八位 + // xxxxxx yy MM dd 75 0 十五位 + // + // 地区: [1-9]\d{5} + // 年的前两位:(18|19|([23]\d)) 1800-2399 + // 年的后两位:\d{2} + // 月份: ((0[1-9])|(10|11|12)) + // 天数: (([0-2][1-9])|10|20|30|31) 闰年不能禁止29+ + // + // 三位顺序码:\d{3} + // 两位顺序码:\d{2} + // 校验码: [0-9Xx] + // + // 十八位:^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$ + // 十五位:^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$ + // + // 总: + // (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$) + case "resident-id": + match = v.checkResidentId(valueStr) + + // Bank card number using LUHN algorithm. + case "bank-card": + match = v.checkLuHn(valueStr) + + // Universal passport format rule: + // Starting with letter, containing only numbers or underscores, length between 6 and 18. + case "passport": + match = gregex.IsMatchString(`^[a-zA-Z]{1}\w{5,17}$`, valueStr) + + // Universal password format rule1: + // Containing any visible chars, length between 6 and 18. + case "password": + match = gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) + + // Universal password format rule2: + // Must meet password rule1, must contain lower and upper letters and numbers. + case "password2": + if gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) && + gregex.IsMatchString(`[a-z]+`, valueStr) && + gregex.IsMatchString(`[A-Z]+`, valueStr) && + gregex.IsMatchString(`\d+`, valueStr) { + match = true + } + + // Universal password format rule3: + // Must meet password rule1, must contain lower and upper letters, numbers and special chars. + case "password3": + if gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) && + gregex.IsMatchString(`[a-z]+`, valueStr) && + gregex.IsMatchString(`[A-Z]+`, valueStr) && + gregex.IsMatchString(`\d+`, valueStr) && + gregex.IsMatchString(`[^a-zA-Z0-9]+`, valueStr) { + match = true + } + + // Json. + case "json": + if json.Valid([]byte(valueStr)) { + match = true + } + + // Integer. + case "integer": + if _, err = strconv.Atoi(valueStr); err == nil { + match = true + } + + // Float. + case "float": + if _, err = strconv.ParseFloat(valueStr, 10); err == nil { + match = true + } + + // Boolean(1,true,on,yes:true | 0,false,off,no,"":false). + case "boolean": + match = false + if _, ok := boolMap[strings.ToLower(valueStr)]; ok { + match = true + } + + // Email. + case "email": + match = gregex.IsMatchString(`^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+)+$`, valueStr) + + // URL + case "url": + match = gregex.IsMatchString(`(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]`, valueStr) + + // Domain + case "domain": + match = gregex.IsMatchString(`^([0-9a-zA-Z][0-9a-zA-Z\-]{0,62}\.)+([a-zA-Z]{0,62})$`, valueStr) + + // IP(IPv4/IPv6). + case "ip": + match = gipv4.Validate(valueStr) || gipv6.Validate(valueStr) + + // IPv4. + case "ipv4": + match = gipv4.Validate(valueStr) + + // IPv6. + case "ipv6": + match = gipv6.Validate(valueStr) + + // MAC. + case "mac": + match = gregex.IsMatchString(`^([0-9A-Fa-f]{2}[\-:]){5}[0-9A-Fa-f]{2}$`, valueStr) + + default: + return match, errors.New("Invalid rule name: " + in.RuleKey) + } + return match, nil } type doCheckValueRecursivelyInput struct { - Value interface{} // Value to be validated. - Type reflect.Type // Struct/map/slice type which to be recursively validated. - OriginKind reflect.Kind // Struct/map/slice kind to be asserted in following switch case. - ErrorMaps map[string]map[string]error // The validated failed error map. - ResultSequenceRules *[]fieldRule // The validated failed rule in sequence. + Value interface{} // Value to be validated. + Type reflect.Type // Struct/map/slice type which to be recursively validated. + OriginKind reflect.Kind // Struct/map/slice kind to be asserted in following switch case. + ErrorMaps map[string]map[string]error // The validated failed error map. + ResultSequenceRules *[]fieldRule // The validated failed rule in sequence. } func (v *Validator) doCheckValueRecursively(ctx context.Context, in doCheckValueRecursivelyInput) { - switch in.OriginKind { - case reflect.Struct: - // Ignore data, rules and messages from parent. - validator := v.Clone() - validator.rules = nil - validator.messages = nil - if err := validator.Data(reflect.New(in.Type).Interface()).Assoc(in.Value).Run(ctx); err != nil { - // It merges the errors into single error map. - for k, m := range err.(*validationError).errors { - in.ErrorMaps[k] = m - } - if in.ResultSequenceRules != nil { - *in.ResultSequenceRules = append(*in.ResultSequenceRules, err.(*validationError).rules...) - } - } - - case reflect.Map: - var ( - dataMap = gconv.Map(in.Value) - mapTypeElem = in.Type.Elem() - mapTypeKind = mapTypeElem.Kind() - ) - for _, item := range dataMap { - v.doCheckValueRecursively(ctx, doCheckValueRecursivelyInput{ - Value: item, - Type: mapTypeElem, - OriginKind: mapTypeKind, - ErrorMaps: in.ErrorMaps, - ResultSequenceRules: in.ResultSequenceRules, - }) - // Bail feature. - if v.bail && len(in.ErrorMaps) > 0 { - break - } - } - - case reflect.Slice, reflect.Array: - var array []interface{} - if gjson.Valid(in.Value) { - array = gconv.Interfaces(gconv.Bytes(in.Value)) - } else { - array = gconv.Interfaces(in.Value) - } - if len(array) == 0 { - return - } - for _, item := range array { - v.doCheckValueRecursively(ctx, doCheckValueRecursivelyInput{ - Value: item, - Type: in.Type.Elem(), - OriginKind: in.Type.Elem().Kind(), - ErrorMaps: in.ErrorMaps, - ResultSequenceRules: in.ResultSequenceRules, - }) - // Bail feature. - if v.bail && len(in.ErrorMaps) > 0 { - break - } - } - } + switch in.OriginKind { + case reflect.Struct: + // Ignore data, rules and messages from parent. + validator := v.Clone() + validator.rules = nil + validator.messages = nil + if err := validator.Data(reflect.New(in.Type).Interface()).Assoc(in.Value).Run(ctx); err != nil { + // It merges the errors into single error map. + for k, m := range err.(*validationError).errors { + in.ErrorMaps[k] = m + } + if in.ResultSequenceRules != nil { + *in.ResultSequenceRules = append(*in.ResultSequenceRules, err.(*validationError).rules...) + } + } + + case reflect.Map: + var ( + dataMap = gconv.Map(in.Value) + mapTypeElem = in.Type.Elem() + mapTypeKind = mapTypeElem.Kind() + ) + for _, item := range dataMap { + v.doCheckValueRecursively(ctx, doCheckValueRecursivelyInput{ + Value: item, + Type: mapTypeElem, + OriginKind: mapTypeKind, + ErrorMaps: in.ErrorMaps, + ResultSequenceRules: in.ResultSequenceRules, + }) + // Bail feature. + if v.bail && len(in.ErrorMaps) > 0 { + break + } + } + + case reflect.Slice, reflect.Array: + var array []interface{} + if gjson.Valid(in.Value) { + array = gconv.Interfaces(gconv.Bytes(in.Value)) + } else { + array = gconv.Interfaces(in.Value) + } + if len(array) == 0 { + return + } + for _, item := range array { + v.doCheckValueRecursively(ctx, doCheckValueRecursivelyInput{ + Value: item, + Type: in.Type.Elem(), + OriginKind: in.Type.Elem().Kind(), + ErrorMaps: in.ErrorMaps, + ResultSequenceRules: in.ResultSequenceRules, + }) + // Bail feature. + if v.bail && len(in.ErrorMaps) > 0 { + break + } + } + } } diff --git a/util/gvalid/gvalid_validator_rule_luhn.go b/util/gvalid/gvalid_validator_rule_luhn.go index 701db2ea191..9d743535d03 100644 --- a/util/gvalid/gvalid_validator_rule_luhn.go +++ b/util/gvalid/gvalid_validator_rule_luhn.go @@ -15,7 +15,7 @@ func (v *Validator) checkLuHn(value string) bool { parity = nDigits % 2 ) for i := 0; i < nDigits; i++ { - digit := int(value[i] - 48) + var digit = int(value[i] - 48) if i%2 == parity { digit *= 2 if digit > 9 { diff --git a/util/gvalid/gvalid_validator_rule_resident_id.go b/util/gvalid/gvalid_validator_rule_resident_id.go index 64848412322..df455592417 100644 --- a/util/gvalid/gvalid_validator_rule_resident_id.go +++ b/util/gvalid/gvalid_validator_rule_resident_id.go @@ -32,7 +32,7 @@ import ( // 十五位:^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$ // // 总: -// (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$). +// (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$) func (v *Validator) checkResidentId(id string) bool { id = strings.ToUpper(strings.TrimSpace(id)) if len(id) != 18 { From 39e7f46a392339ee070a908285c359a1dc628b1f Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 23:17:58 +0800 Subject: [PATCH 59/70] fix --- util/gvalid/gvalid_validator_check_value.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/util/gvalid/gvalid_validator_check_value.go b/util/gvalid/gvalid_validator_check_value.go index 9e5cf1c000d..f4488508334 100644 --- a/util/gvalid/gvalid_validator_check_value.go +++ b/util/gvalid/gvalid_validator_check_value.go @@ -34,13 +34,12 @@ type iTime interface { } type doCheckValueInput struct { - Name string // Name specifies the name of parameter `value`. - Value interface{} // Value specifies the value for the rules to be validated. - Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. - Messages interface{} // Messages specifies the custom error messages for this rule from parameters - // input, which is usually type of map/slice. - DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be type of map/struct or a nil value. - DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally + Name string // Name specifies the name of parameter `value`. + Value interface{} // Value specifies the value for the rules to be validated. + Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. + Messages interface{} // Messages specifies the custom error messages for this rule from parameters input, which is usually type of map/slice. + DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be type of map/struct or a nil value. + DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally } // doCheckSingleValue does the really rules validation for single key-value. @@ -308,7 +307,7 @@ func (v *Validator) doCheckSingleBuildInRules(ctx context.Context, in doCheckBui match = true } else { var ( - msg string + msg string ) msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) return match, errors.New(msg) @@ -607,4 +606,4 @@ func (v *Validator) doCheckValueRecursively(ctx context.Context, in doCheckValue } } } -} +} \ No newline at end of file From b75815a310162761fc376411fb352c30151663fb Mon Sep 17 00:00:00 2001 From: houseme Date: Thu, 12 May 2022 23:19:48 +0800 Subject: [PATCH 60/70] Update gvalid_validator_check_value.go --- util/gvalid/gvalid_validator_check_value.go | 1156 +++++++++---------- 1 file changed, 578 insertions(+), 578 deletions(-) diff --git a/util/gvalid/gvalid_validator_check_value.go b/util/gvalid/gvalid_validator_check_value.go index f4488508334..bd69f9f77ce 100644 --- a/util/gvalid/gvalid_validator_check_value.go +++ b/util/gvalid/gvalid_validator_check_value.go @@ -7,603 +7,603 @@ package gvalid import ( - "context" - "errors" - "reflect" - "strconv" - "strings" - "time" - - "github.com/gogf/gf/v2/container/gvar" - "github.com/gogf/gf/v2/encoding/gjson" - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/internal/json" - "github.com/gogf/gf/v2/net/gipv4" - "github.com/gogf/gf/v2/net/gipv6" - "github.com/gogf/gf/v2/os/gtime" - "github.com/gogf/gf/v2/text/gregex" - "github.com/gogf/gf/v2/text/gstr" - "github.com/gogf/gf/v2/util/gconv" - "github.com/gogf/gf/v2/util/gutil" + "context" + "errors" + "reflect" + "strconv" + "strings" + "time" + + "github.com/gogf/gf/v2/container/gvar" + "github.com/gogf/gf/v2/encoding/gjson" + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/internal/json" + "github.com/gogf/gf/v2/net/gipv4" + "github.com/gogf/gf/v2/net/gipv6" + "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/text/gregex" + "github.com/gogf/gf/v2/text/gstr" + "github.com/gogf/gf/v2/util/gconv" + "github.com/gogf/gf/v2/util/gutil" ) type iTime interface { - Date() (year int, month time.Month, day int) - IsZero() bool + Date() (year int, month time.Month, day int) + IsZero() bool } type doCheckValueInput struct { - Name string // Name specifies the name of parameter `value`. - Value interface{} // Value specifies the value for the rules to be validated. - Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. - Messages interface{} // Messages specifies the custom error messages for this rule from parameters input, which is usually type of map/slice. - DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be type of map/struct or a nil value. - DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally + Name string // Name specifies the name of parameter `value`. + Value interface{} // Value specifies the value for the rules to be validated. + Rule string // Rule specifies the validation rules string, like "required", "required|between:1,100", etc. + Messages interface{} // Messages specifies the custom error messages for this rule from parameters input, which is usually type of map/slice. + DataRaw interface{} // DataRaw specifies the `raw data` which is passed to the Validator. It might be type of map/struct or a nil value. + DataMap map[string]interface{} // DataMap specifies the map that is converted from `dataRaw`. It is usually used internally } // doCheckSingleValue does the really rules validation for single key-value. func (v *Validator) doCheckValue(ctx context.Context, in doCheckValueInput) Error { - // If there's no validation rules, it does nothing and returns quickly. - if in.Rule == "" { - return nil - } - // It converts value to string and then does the validation. - var ( - // Do not trim it as the space is also part of the value. - ruleErrorMap = make(map[string]error) - ) - // Custom error messages handling. - var ( - msgArray = make([]string, 0) - customMsgMap = make(map[string]string) - ) - switch messages := in.Messages.(type) { - case string: - msgArray = strings.Split(messages, "|") - - default: - for k, message := range gconv.Map(in.Messages) { - customMsgMap[k] = gconv.String(message) - } - } - // Handle the char '|' in the rule, - // which makes this rule separated into multiple rules. - ruleItems := strings.Split(strings.TrimSpace(in.Rule), "|") - for i := 0; ; { - array := strings.Split(ruleItems[i], ":") - _, ok := allSupportedRules[array[0]] - if !ok && v.getRuleFunc(array[0]) == nil { - if i > 0 && ruleItems[i-1][:5] == "regex" { - ruleItems[i-1] += "|" + ruleItems[i] - ruleItems = append(ruleItems[:i], ruleItems[i+1:]...) - } else { - return newValidationErrorByStr( - internalRulesErrRuleName, - errors.New(internalRulesErrRuleName+": "+ruleItems[i]), - ) - } - } else { - i++ - } - if i == len(ruleItems) { - break - } - } - var ( - hasBailRule = v.bail - hasCaseInsensitive = v.caseInsensitive - ) - for index := 0; index < len(ruleItems); { - var ( - err error - match = false // whether this rule is matched(has no error) - results = ruleRegex.FindStringSubmatch(ruleItems[index]) // split single rule. - ruleKey = gstr.Trim(results[1]) // rule key like "max" in rule "max: 6" - rulePattern = gstr.Trim(results[2]) // rule pattern is like "6" in rule:"max:6" - customRuleFunc RuleFunc - ) - - if !hasBailRule && ruleKey == ruleNameBail { - hasBailRule = true - } - - if !hasCaseInsensitive && ruleKey == ruleNameCi { - hasCaseInsensitive = true - } - - // Ignore logic executing for marked rules. - if markedRuleMap[ruleKey] { - index++ - continue - } - - if len(msgArray) > index { - customMsgMap[ruleKey] = strings.TrimSpace(msgArray[index]) - } - - // =========================================================================================== - // Custom rule handling - // =========================================================================================== - // 1. It firstly checks and uses the custom registered rules functions in the current Validator. - // 2. It secondly checks and uses the globally registered rules functions. - // 3. It finally checks and uses the build-in rules functions. - customRuleFunc = v.getRuleFunc(ruleKey) - if customRuleFunc != nil { - // It checks custom validation rules with most priority. - message := v.getErrorMessageByRule(ctx, ruleKey, customMsgMap) - if err = customRuleFunc(ctx, RuleFuncInput{ - Rule: ruleItems[index], - Message: message, - Value: gvar.New(in.Value), - Data: gvar.New(in.DataRaw), - }); err != nil { - match = false - // The error should have stack info to indicate the error position. - if !gerror.HasStack(err) { - err = gerror.NewCodeSkip(gcode.CodeValidationFailed, 1, err.Error()) - } - // The error should have error code that is `gcode.CodeValidationFailed`. - if gerror.Code(err) == gcode.CodeNil { - if e, ok := err.(*gerror.Error); ok { - e.SetCode(gcode.CodeValidationFailed) - } - } - ruleErrorMap[ruleKey] = err - } else { - match = true - } - } else { - // It checks build-in validation rules if there's no custom rule. - match, err = v.doCheckSingleBuildInRules( - ctx, - doCheckBuildInRulesInput{ - Index: index, - Value: in.Value, - RuleKey: ruleKey, - RulePattern: rulePattern, - RuleItems: ruleItems, - DataMap: in.DataMap, - CustomMsgMap: customMsgMap, - CaseInsensitive: hasCaseInsensitive, - }, - ) - if !match && err != nil { - ruleErrorMap[ruleKey] = err - } - } - - // Error message handling. - if !match { - // It does nothing if the error message for this rule - // is already set in previous validation. - if _, ok := ruleErrorMap[ruleKey]; !ok { - ruleErrorMap[ruleKey] = errors.New(v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)) - } - - // Error variable replacement for error message. - if err = ruleErrorMap[ruleKey]; !gerror.HasStack(err) { - var s string - s = gstr.ReplaceByMap(err.Error(), map[string]string{ - "{value}": gconv.String(in.Value), - "{pattern}": rulePattern, - "{attribute}": in.Name, - }) - s, _ = gregex.ReplaceString(`\s{2,}`, ` `, s) - ruleErrorMap[ruleKey] = errors.New(s) - } - - // If it is with error and there's bail rule, - // it then does not continue validating for left rules. - if hasBailRule { - break - } - } - index++ - } - if len(ruleErrorMap) > 0 { - return newValidationError( - gcode.CodeValidationFailed, - []fieldRule{{Name: in.Name, Rule: in.Rule}}, - map[string]map[string]error{ - in.Name: ruleErrorMap, - }, - ) - } - return nil + // If there's no validation rules, it does nothing and returns quickly. + if in.Rule == "" { + return nil + } + // It converts value to string and then does the validation. + var ( + // Do not trim it as the space is also part of the value. + ruleErrorMap = make(map[string]error) + ) + // Custom error messages handling. + var ( + msgArray = make([]string, 0) + customMsgMap = make(map[string]string) + ) + switch messages := in.Messages.(type) { + case string: + msgArray = strings.Split(messages, "|") + + default: + for k, message := range gconv.Map(in.Messages) { + customMsgMap[k] = gconv.String(message) + } + } + // Handle the char '|' in the rule, + // which makes this rule separated into multiple rules. + ruleItems := strings.Split(strings.TrimSpace(in.Rule), "|") + for i := 0; ; { + array := strings.Split(ruleItems[i], ":") + _, ok := allSupportedRules[array[0]] + if !ok && v.getRuleFunc(array[0]) == nil { + if i > 0 && ruleItems[i-1][:5] == "regex" { + ruleItems[i-1] += "|" + ruleItems[i] + ruleItems = append(ruleItems[:i], ruleItems[i+1:]...) + } else { + return newValidationErrorByStr( + internalRulesErrRuleName, + errors.New(internalRulesErrRuleName+": "+ruleItems[i]), + ) + } + } else { + i++ + } + if i == len(ruleItems) { + break + } + } + var ( + hasBailRule = v.bail + hasCaseInsensitive = v.caseInsensitive + ) + for index := 0; index < len(ruleItems); { + var ( + err error + match = false // whether this rule is matched(has no error) + results = ruleRegex.FindStringSubmatch(ruleItems[index]) // split single rule. + ruleKey = gstr.Trim(results[1]) // rule key like "max" in rule "max: 6" + rulePattern = gstr.Trim(results[2]) // rule pattern is like "6" in rule:"max:6" + customRuleFunc RuleFunc + ) + + if !hasBailRule && ruleKey == ruleNameBail { + hasBailRule = true + } + + if !hasCaseInsensitive && ruleKey == ruleNameCi { + hasCaseInsensitive = true + } + + // Ignore logic executing for marked rules. + if markedRuleMap[ruleKey] { + index++ + continue + } + + if len(msgArray) > index { + customMsgMap[ruleKey] = strings.TrimSpace(msgArray[index]) + } + + // =========================================================================================== + // Custom rule handling + // =========================================================================================== + // 1. It firstly checks and uses the custom registered rules functions in the current Validator. + // 2. It secondly checks and uses the globally registered rules functions. + // 3. It finally checks and uses the build-in rules functions. + customRuleFunc = v.getRuleFunc(ruleKey) + if customRuleFunc != nil { + // It checks custom validation rules with most priority. + message := v.getErrorMessageByRule(ctx, ruleKey, customMsgMap) + if err = customRuleFunc(ctx, RuleFuncInput{ + Rule: ruleItems[index], + Message: message, + Value: gvar.New(in.Value), + Data: gvar.New(in.DataRaw), + }); err != nil { + match = false + // The error should have stack info to indicate the error position. + if !gerror.HasStack(err) { + err = gerror.NewCodeSkip(gcode.CodeValidationFailed, 1, err.Error()) + } + // The error should have error code that is `gcode.CodeValidationFailed`. + if gerror.Code(err) == gcode.CodeNil { + if e, ok := err.(*gerror.Error); ok { + e.SetCode(gcode.CodeValidationFailed) + } + } + ruleErrorMap[ruleKey] = err + } else { + match = true + } + } else { + // It checks build-in validation rules if there's no custom rule. + match, err = v.doCheckSingleBuildInRules( + ctx, + doCheckBuildInRulesInput{ + Index: index, + Value: in.Value, + RuleKey: ruleKey, + RulePattern: rulePattern, + RuleItems: ruleItems, + DataMap: in.DataMap, + CustomMsgMap: customMsgMap, + CaseInsensitive: hasCaseInsensitive, + }, + ) + if !match && err != nil { + ruleErrorMap[ruleKey] = err + } + } + + // Error message handling. + if !match { + // It does nothing if the error message for this rule + // is already set in previous validation. + if _, ok := ruleErrorMap[ruleKey]; !ok { + ruleErrorMap[ruleKey] = errors.New(v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)) + } + + // Error variable replacement for error message. + if err = ruleErrorMap[ruleKey]; !gerror.HasStack(err) { + var s string + s = gstr.ReplaceByMap(err.Error(), map[string]string{ + "{value}": gconv.String(in.Value), + "{pattern}": rulePattern, + "{attribute}": in.Name, + }) + s, _ = gregex.ReplaceString(`\s{2,}`, ` `, s) + ruleErrorMap[ruleKey] = errors.New(s) + } + + // If it is with error and there's bail rule, + // it then does not continue validating for left rules. + if hasBailRule { + break + } + } + index++ + } + if len(ruleErrorMap) > 0 { + return newValidationError( + gcode.CodeValidationFailed, + []fieldRule{{Name: in.Name, Rule: in.Rule}}, + map[string]map[string]error{ + in.Name: ruleErrorMap, + }, + ) + } + return nil } type doCheckBuildInRulesInput struct { - Index int // Index of RuleKey in RuleItems. - Value interface{} // Value to be validated. - RuleKey string // RuleKey is like the "max" in rule "max: 6" - RulePattern string // RulePattern is like "6" in rule:"max:6" - RuleItems []string // RuleItems are all the rules that should be validated on single field, like: []string{"required", "min:1"} - DataMap map[string]interface{} // Parameter map. - CustomMsgMap map[string]string // Custom error message map. - CaseInsensitive bool // Case-Insensitive comparison. + Index int // Index of RuleKey in RuleItems. + Value interface{} // Value to be validated. + RuleKey string // RuleKey is like the "max" in rule "max: 6" + RulePattern string // RulePattern is like "6" in rule:"max:6" + RuleItems []string // RuleItems are all the rules that should be validated on single field, like: []string{"required", "min:1"} + DataMap map[string]interface{} // Parameter map. + CustomMsgMap map[string]string // Custom error message map. + CaseInsensitive bool // Case-Insensitive comparison. } func (v *Validator) doCheckSingleBuildInRules(ctx context.Context, in doCheckBuildInRulesInput) (match bool, err error) { - valueStr := gconv.String(in.Value) - switch in.RuleKey { - // Required rules. - case - "required", - "required-if", - "required-unless", - "required-with", - "required-with-all", - "required-without", - "required-without-all": - match = v.checkRequired(checkRequiredInput{ - Value: in.Value, - RuleKey: in.RuleKey, - RulePattern: in.RulePattern, - DataMap: in.DataMap, - CaseInsensitive: in.CaseInsensitive, - }) - - // Length rules. - // It also supports length of unicode string. - case - "length", - "min-length", - "max-length", - "size": - if msg := v.checkLength(ctx, valueStr, in.RuleKey, in.RulePattern, in.CustomMsgMap); msg != "" { - return match, errors.New(msg) - } else { - match = true - } - - // Range rules. - case - "min", - "max", - "between": - if msg := v.checkRange(ctx, valueStr, in.RuleKey, in.RulePattern, in.CustomMsgMap); msg != "" { - return match, errors.New(msg) - } else { - match = true - } - - // Custom regular expression. - case "regex": - // It here should check the rule as there might be special char '|' in it. - for i := in.Index + 1; i < len(in.RuleItems); i++ { - if !gregex.IsMatchString(singleRulePattern, in.RuleItems[i]) { - in.RulePattern += "|" + in.RuleItems[i] - in.Index++ - } - } - match = gregex.IsMatchString(in.RulePattern, valueStr) - - // Date rules. - case "date": - // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. - if value, ok := in.Value.(iTime); ok { - return !value.IsZero(), nil - } - match = gregex.IsMatchString(`\d{4}[\.\-\_/]{0,1}\d{2}[\.\-\_/]{0,1}\d{2}`, valueStr) - - // Datetime rule. - case "datetime": - // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. - if value, ok := in.Value.(iTime); ok { - return !value.IsZero(), nil - } - if _, err = gtime.StrToTimeFormat(valueStr, `Y-m-d H:i:s`); err == nil { - match = true - } - - // Date rule with specified format. - case "date-format": - // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. - if value, ok := in.Value.(iTime); ok { - return !value.IsZero(), nil - } - if _, err = gtime.StrToTimeFormat(valueStr, in.RulePattern); err == nil { - match = true - } else { - var ( - msg string - ) - msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) - return match, errors.New(msg) - } - - // Values of two fields should be equal as string. - case "same": - _, foundValue := gutil.MapPossibleItemByKey(in.DataMap, in.RulePattern) - if foundValue != nil { - if in.CaseInsensitive { - match = strings.EqualFold(valueStr, gconv.String(foundValue)) - } else { - match = strings.Compare(valueStr, gconv.String(foundValue)) == 0 - } - } - if !match { - var msg string - msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) - return match, errors.New(msg) - } - - // Values of two fields should not be equal as string. - case "different": - match = true - _, foundValue := gutil.MapPossibleItemByKey(in.DataMap, in.RulePattern) - if foundValue != nil { - if in.CaseInsensitive { - match = !strings.EqualFold(valueStr, gconv.String(foundValue)) - } else { - match = strings.Compare(valueStr, gconv.String(foundValue)) != 0 - } - } - if !match { - var msg string - msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) - return match, errors.New(msg) - } - - // Field value should be in range of. - case "in": - for _, value := range gstr.SplitAndTrim(in.RulePattern, ",") { - if in.CaseInsensitive { - match = strings.EqualFold(valueStr, strings.TrimSpace(value)) - } else { - match = strings.Compare(valueStr, strings.TrimSpace(value)) == 0 - } - if match { - break - } - } - - // Field value should not be in range of. - case "not-in": - match = true - for _, value := range gstr.SplitAndTrim(in.RulePattern, ",") { - if in.CaseInsensitive { - match = !strings.EqualFold(valueStr, strings.TrimSpace(value)) - } else { - match = strings.Compare(valueStr, strings.TrimSpace(value)) != 0 - } - if !match { - break - } - } - - // Phone format validation. - // 1. China Mobile: - // 134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, - // 178(4G), 147(Net); - // 172 - // - // 2. China Unicom: - // 130, 131, 132, 155, 156, 185, 186 ,176(4G), 145(Net), 175 - // - // 3. China Telecom: - // 133, 153, 180, 181, 189, 177(4G) - // - // 4. Satelite: - // 1349 - // - // 5. Virtual: - // 170, 173 - // - // 6. 2018: - // 16x, 19x - case "phone": - match = gregex.IsMatchString(`^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^16[\d]{9}$|^17[0,2,3,5,6,7,8]{1}\d{8}$|^18[\d]{9}$|^19[\d]{9}$`, valueStr) - - // Loose mobile phone number verification(宽松的手机号验证) - // As long as the 11 digit numbers beginning with - // 13, 14, 15, 16, 17, 18, 19 can pass the verification (只要满足 13、14、15、16、17、18、19开头的11位数字都可以通过验证) - case "phone-loose": - match = gregex.IsMatchString(`^1(3|4|5|6|7|8|9)\d{9}$`, valueStr) - - // Telephone number: - // "XXXX-XXXXXXX" - // "XXXX-XXXXXXXX" - // "XXX-XXXXXXX" - // "XXX-XXXXXXXX" - // "XXXXXXX" - // "XXXXXXXX" - case "telephone": - match = gregex.IsMatchString(`^((\d{3,4})|\d{3,4}-)?\d{7,8}$`, valueStr) - - // QQ number: from 10000. - case "qq": - match = gregex.IsMatchString(`^[1-9][0-9]{4,}$`, valueStr) - - // Postcode number. - case "postcode": - match = gregex.IsMatchString(`^\d{6}$`, valueStr) - - // China resident id number. - // - // xxxxxx yyyy MM dd 375 0 十八位 - // xxxxxx yy MM dd 75 0 十五位 - // - // 地区: [1-9]\d{5} - // 年的前两位:(18|19|([23]\d)) 1800-2399 - // 年的后两位:\d{2} - // 月份: ((0[1-9])|(10|11|12)) - // 天数: (([0-2][1-9])|10|20|30|31) 闰年不能禁止29+ - // - // 三位顺序码:\d{3} - // 两位顺序码:\d{2} - // 校验码: [0-9Xx] - // - // 十八位:^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$ - // 十五位:^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$ - // - // 总: - // (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$) - case "resident-id": - match = v.checkResidentId(valueStr) - - // Bank card number using LUHN algorithm. - case "bank-card": - match = v.checkLuHn(valueStr) - - // Universal passport format rule: - // Starting with letter, containing only numbers or underscores, length between 6 and 18. - case "passport": - match = gregex.IsMatchString(`^[a-zA-Z]{1}\w{5,17}$`, valueStr) - - // Universal password format rule1: - // Containing any visible chars, length between 6 and 18. - case "password": - match = gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) - - // Universal password format rule2: - // Must meet password rule1, must contain lower and upper letters and numbers. - case "password2": - if gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) && - gregex.IsMatchString(`[a-z]+`, valueStr) && - gregex.IsMatchString(`[A-Z]+`, valueStr) && - gregex.IsMatchString(`\d+`, valueStr) { - match = true - } - - // Universal password format rule3: - // Must meet password rule1, must contain lower and upper letters, numbers and special chars. - case "password3": - if gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) && - gregex.IsMatchString(`[a-z]+`, valueStr) && - gregex.IsMatchString(`[A-Z]+`, valueStr) && - gregex.IsMatchString(`\d+`, valueStr) && - gregex.IsMatchString(`[^a-zA-Z0-9]+`, valueStr) { - match = true - } - - // Json. - case "json": - if json.Valid([]byte(valueStr)) { - match = true - } - - // Integer. - case "integer": - if _, err = strconv.Atoi(valueStr); err == nil { - match = true - } - - // Float. - case "float": - if _, err = strconv.ParseFloat(valueStr, 10); err == nil { - match = true - } - - // Boolean(1,true,on,yes:true | 0,false,off,no,"":false). - case "boolean": - match = false - if _, ok := boolMap[strings.ToLower(valueStr)]; ok { - match = true - } - - // Email. - case "email": - match = gregex.IsMatchString(`^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+)+$`, valueStr) - - // URL - case "url": - match = gregex.IsMatchString(`(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]`, valueStr) - - // Domain - case "domain": - match = gregex.IsMatchString(`^([0-9a-zA-Z][0-9a-zA-Z\-]{0,62}\.)+([a-zA-Z]{0,62})$`, valueStr) - - // IP(IPv4/IPv6). - case "ip": - match = gipv4.Validate(valueStr) || gipv6.Validate(valueStr) - - // IPv4. - case "ipv4": - match = gipv4.Validate(valueStr) - - // IPv6. - case "ipv6": - match = gipv6.Validate(valueStr) - - // MAC. - case "mac": - match = gregex.IsMatchString(`^([0-9A-Fa-f]{2}[\-:]){5}[0-9A-Fa-f]{2}$`, valueStr) - - default: - return match, errors.New("Invalid rule name: " + in.RuleKey) - } - return match, nil + valueStr := gconv.String(in.Value) + switch in.RuleKey { + // Required rules. + case + "required", + "required-if", + "required-unless", + "required-with", + "required-with-all", + "required-without", + "required-without-all": + match = v.checkRequired(checkRequiredInput{ + Value: in.Value, + RuleKey: in.RuleKey, + RulePattern: in.RulePattern, + DataMap: in.DataMap, + CaseInsensitive: in.CaseInsensitive, + }) + + // Length rules. + // It also supports length of unicode string. + case + "length", + "min-length", + "max-length", + "size": + if msg := v.checkLength(ctx, valueStr, in.RuleKey, in.RulePattern, in.CustomMsgMap); msg != "" { + return match, errors.New(msg) + } else { + match = true + } + + // Range rules. + case + "min", + "max", + "between": + if msg := v.checkRange(ctx, valueStr, in.RuleKey, in.RulePattern, in.CustomMsgMap); msg != "" { + return match, errors.New(msg) + } else { + match = true + } + + // Custom regular expression. + case "regex": + // It here should check the rule as there might be special char '|' in it. + for i := in.Index + 1; i < len(in.RuleItems); i++ { + if !gregex.IsMatchString(singleRulePattern, in.RuleItems[i]) { + in.RulePattern += "|" + in.RuleItems[i] + in.Index++ + } + } + match = gregex.IsMatchString(in.RulePattern, valueStr) + + // Date rules. + case "date": + // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. + if value, ok := in.Value.(iTime); ok { + return !value.IsZero(), nil + } + match = gregex.IsMatchString(`\d{4}[\.\-\_/]{0,1}\d{2}[\.\-\_/]{0,1}\d{2}`, valueStr) + + // Datetime rule. + case "datetime": + // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. + if value, ok := in.Value.(iTime); ok { + return !value.IsZero(), nil + } + if _, err = gtime.StrToTimeFormat(valueStr, `Y-m-d H:i:s`); err == nil { + match = true + } + + // Date rule with specified format. + case "date-format": + // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. + if value, ok := in.Value.(iTime); ok { + return !value.IsZero(), nil + } + if _, err = gtime.StrToTimeFormat(valueStr, in.RulePattern); err == nil { + match = true + } else { + var ( + msg string + ) + msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) + return match, errors.New(msg) + } + + // Values of two fields should be equal as string. + case "same": + _, foundValue := gutil.MapPossibleItemByKey(in.DataMap, in.RulePattern) + if foundValue != nil { + if in.CaseInsensitive { + match = strings.EqualFold(valueStr, gconv.String(foundValue)) + } else { + match = strings.Compare(valueStr, gconv.String(foundValue)) == 0 + } + } + if !match { + var msg string + msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) + return match, errors.New(msg) + } + + // Values of two fields should not be equal as string. + case "different": + match = true + _, foundValue := gutil.MapPossibleItemByKey(in.DataMap, in.RulePattern) + if foundValue != nil { + if in.CaseInsensitive { + match = !strings.EqualFold(valueStr, gconv.String(foundValue)) + } else { + match = strings.Compare(valueStr, gconv.String(foundValue)) != 0 + } + } + if !match { + var msg string + msg = v.getErrorMessageByRule(ctx, in.RuleKey, in.CustomMsgMap) + return match, errors.New(msg) + } + + // Field value should be in range of. + case "in": + for _, value := range gstr.SplitAndTrim(in.RulePattern, ",") { + if in.CaseInsensitive { + match = strings.EqualFold(valueStr, strings.TrimSpace(value)) + } else { + match = strings.Compare(valueStr, strings.TrimSpace(value)) == 0 + } + if match { + break + } + } + + // Field value should not be in range of. + case "not-in": + match = true + for _, value := range gstr.SplitAndTrim(in.RulePattern, ",") { + if in.CaseInsensitive { + match = !strings.EqualFold(valueStr, strings.TrimSpace(value)) + } else { + match = strings.Compare(valueStr, strings.TrimSpace(value)) != 0 + } + if !match { + break + } + } + + // Phone format validation. + // 1. China Mobile: + // 134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, + // 178(4G), 147(Net); + // 172 + // + // 2. China Unicom: + // 130, 131, 132, 155, 156, 185, 186 ,176(4G), 145(Net), 175 + // + // 3. China Telecom: + // 133, 153, 180, 181, 189, 177(4G) + // + // 4. Satelite: + // 1349 + // + // 5. Virtual: + // 170, 173 + // + // 6. 2018: + // 16x, 19x + case "phone": + match = gregex.IsMatchString(`^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^16[\d]{9}$|^17[0,2,3,5,6,7,8]{1}\d{8}$|^18[\d]{9}$|^19[\d]{9}$`, valueStr) + + // Loose mobile phone number verification(宽松的手机号验证) + // As long as the 11 digit numbers beginning with + // 13, 14, 15, 16, 17, 18, 19 can pass the verification (只要满足 13、14、15、16、17、18、19开头的11位数字都可以通过验证) + case "phone-loose": + match = gregex.IsMatchString(`^1(3|4|5|6|7|8|9)\d{9}$`, valueStr) + + // Telephone number: + // "XXXX-XXXXXXX" + // "XXXX-XXXXXXXX" + // "XXX-XXXXXXX" + // "XXX-XXXXXXXX" + // "XXXXXXX" + // "XXXXXXXX" + case "telephone": + match = gregex.IsMatchString(`^((\d{3,4})|\d{3,4}-)?\d{7,8}$`, valueStr) + + // QQ number: from 10000. + case "qq": + match = gregex.IsMatchString(`^[1-9][0-9]{4,}$`, valueStr) + + // Postcode number. + case "postcode": + match = gregex.IsMatchString(`^\d{6}$`, valueStr) + + // China resident id number. + // + // xxxxxx yyyy MM dd 375 0 十八位 + // xxxxxx yy MM dd 75 0 十五位 + // + // 地区: [1-9]\d{5} + // 年的前两位:(18|19|([23]\d)) 1800-2399 + // 年的后两位:\d{2} + // 月份: ((0[1-9])|(10|11|12)) + // 天数: (([0-2][1-9])|10|20|30|31) 闰年不能禁止29+ + // + // 三位顺序码:\d{3} + // 两位顺序码:\d{2} + // 校验码: [0-9Xx] + // + // 十八位:^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$ + // 十五位:^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$ + // + // 总: + // (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$) + case "resident-id": + match = v.checkResidentId(valueStr) + + // Bank card number using LUHN algorithm. + case "bank-card": + match = v.checkLuHn(valueStr) + + // Universal passport format rule: + // Starting with letter, containing only numbers or underscores, length between 6 and 18. + case "passport": + match = gregex.IsMatchString(`^[a-zA-Z]{1}\w{5,17}$`, valueStr) + + // Universal password format rule1: + // Containing any visible chars, length between 6 and 18. + case "password": + match = gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) + + // Universal password format rule2: + // Must meet password rule1, must contain lower and upper letters and numbers. + case "password2": + if gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) && + gregex.IsMatchString(`[a-z]+`, valueStr) && + gregex.IsMatchString(`[A-Z]+`, valueStr) && + gregex.IsMatchString(`\d+`, valueStr) { + match = true + } + + // Universal password format rule3: + // Must meet password rule1, must contain lower and upper letters, numbers and special chars. + case "password3": + if gregex.IsMatchString(`^[\w\S]{6,18}$`, valueStr) && + gregex.IsMatchString(`[a-z]+`, valueStr) && + gregex.IsMatchString(`[A-Z]+`, valueStr) && + gregex.IsMatchString(`\d+`, valueStr) && + gregex.IsMatchString(`[^a-zA-Z0-9]+`, valueStr) { + match = true + } + + // Json. + case "json": + if json.Valid([]byte(valueStr)) { + match = true + } + + // Integer. + case "integer": + if _, err = strconv.Atoi(valueStr); err == nil { + match = true + } + + // Float. + case "float": + if _, err = strconv.ParseFloat(valueStr, 10); err == nil { + match = true + } + + // Boolean(1,true,on,yes:true | 0,false,off,no,"":false). + case "boolean": + match = false + if _, ok := boolMap[strings.ToLower(valueStr)]; ok { + match = true + } + + // Email. + case "email": + match = gregex.IsMatchString(`^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+)+$`, valueStr) + + // URL + case "url": + match = gregex.IsMatchString(`(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]`, valueStr) + + // Domain + case "domain": + match = gregex.IsMatchString(`^([0-9a-zA-Z][0-9a-zA-Z\-]{0,62}\.)+([a-zA-Z]{0,62})$`, valueStr) + + // IP(IPv4/IPv6). + case "ip": + match = gipv4.Validate(valueStr) || gipv6.Validate(valueStr) + + // IPv4. + case "ipv4": + match = gipv4.Validate(valueStr) + + // IPv6. + case "ipv6": + match = gipv6.Validate(valueStr) + + // MAC. + case "mac": + match = gregex.IsMatchString(`^([0-9A-Fa-f]{2}[\-:]){5}[0-9A-Fa-f]{2}$`, valueStr) + + default: + return match, errors.New("Invalid rule name: " + in.RuleKey) + } + return match, nil } type doCheckValueRecursivelyInput struct { - Value interface{} // Value to be validated. - Type reflect.Type // Struct/map/slice type which to be recursively validated. - OriginKind reflect.Kind // Struct/map/slice kind to be asserted in following switch case. - ErrorMaps map[string]map[string]error // The validated failed error map. - ResultSequenceRules *[]fieldRule // The validated failed rule in sequence. + Value interface{} // Value to be validated. + Type reflect.Type // Struct/map/slice type which to be recursively validated. + OriginKind reflect.Kind // Struct/map/slice kind to be asserted in following switch case. + ErrorMaps map[string]map[string]error // The validated failed error map. + ResultSequenceRules *[]fieldRule // The validated failed rule in sequence. } func (v *Validator) doCheckValueRecursively(ctx context.Context, in doCheckValueRecursivelyInput) { - switch in.OriginKind { - case reflect.Struct: - // Ignore data, rules and messages from parent. - validator := v.Clone() - validator.rules = nil - validator.messages = nil - if err := validator.Data(reflect.New(in.Type).Interface()).Assoc(in.Value).Run(ctx); err != nil { - // It merges the errors into single error map. - for k, m := range err.(*validationError).errors { - in.ErrorMaps[k] = m - } - if in.ResultSequenceRules != nil { - *in.ResultSequenceRules = append(*in.ResultSequenceRules, err.(*validationError).rules...) - } - } - - case reflect.Map: - var ( - dataMap = gconv.Map(in.Value) - mapTypeElem = in.Type.Elem() - mapTypeKind = mapTypeElem.Kind() - ) - for _, item := range dataMap { - v.doCheckValueRecursively(ctx, doCheckValueRecursivelyInput{ - Value: item, - Type: mapTypeElem, - OriginKind: mapTypeKind, - ErrorMaps: in.ErrorMaps, - ResultSequenceRules: in.ResultSequenceRules, - }) - // Bail feature. - if v.bail && len(in.ErrorMaps) > 0 { - break - } - } - - case reflect.Slice, reflect.Array: - var array []interface{} - if gjson.Valid(in.Value) { - array = gconv.Interfaces(gconv.Bytes(in.Value)) - } else { - array = gconv.Interfaces(in.Value) - } - if len(array) == 0 { - return - } - for _, item := range array { - v.doCheckValueRecursively(ctx, doCheckValueRecursivelyInput{ - Value: item, - Type: in.Type.Elem(), - OriginKind: in.Type.Elem().Kind(), - ErrorMaps: in.ErrorMaps, - ResultSequenceRules: in.ResultSequenceRules, - }) - // Bail feature. - if v.bail && len(in.ErrorMaps) > 0 { - break - } - } - } -} \ No newline at end of file + switch in.OriginKind { + case reflect.Struct: + // Ignore data, rules and messages from parent. + validator := v.Clone() + validator.rules = nil + validator.messages = nil + if err := validator.Data(reflect.New(in.Type).Interface()).Assoc(in.Value).Run(ctx); err != nil { + // It merges the errors into single error map. + for k, m := range err.(*validationError).errors { + in.ErrorMaps[k] = m + } + if in.ResultSequenceRules != nil { + *in.ResultSequenceRules = append(*in.ResultSequenceRules, err.(*validationError).rules...) + } + } + + case reflect.Map: + var ( + dataMap = gconv.Map(in.Value) + mapTypeElem = in.Type.Elem() + mapTypeKind = mapTypeElem.Kind() + ) + for _, item := range dataMap { + v.doCheckValueRecursively(ctx, doCheckValueRecursivelyInput{ + Value: item, + Type: mapTypeElem, + OriginKind: mapTypeKind, + ErrorMaps: in.ErrorMaps, + ResultSequenceRules: in.ResultSequenceRules, + }) + // Bail feature. + if v.bail && len(in.ErrorMaps) > 0 { + break + } + } + + case reflect.Slice, reflect.Array: + var array []interface{} + if gjson.Valid(in.Value) { + array = gconv.Interfaces(gconv.Bytes(in.Value)) + } else { + array = gconv.Interfaces(in.Value) + } + if len(array) == 0 { + return + } + for _, item := range array { + v.doCheckValueRecursively(ctx, doCheckValueRecursivelyInput{ + Value: item, + Type: in.Type.Elem(), + OriginKind: in.Type.Elem().Kind(), + ErrorMaps: in.ErrorMaps, + ResultSequenceRules: in.ResultSequenceRules, + }) + // Bail feature. + if v.bail && len(in.ErrorMaps) > 0 { + break + } + } + } +} From 82c33c9794136d1bc51a630dbf26afd3c5ab9cff Mon Sep 17 00:00:00 2001 From: houseme Date: Fri, 13 May 2022 00:27:07 +0800 Subject: [PATCH 61/70] up --- contrib/registry/polaris/polaris.go | 204 ++++++++++++ contrib/registry/polaris/polaris_discovery.go | 42 +++ contrib/registry/polaris/polaris_registry.go | 299 ------------------ ...laris_registry_test.go => polaris_test.go} | 0 contrib/registry/polaris/polaris_watcher.go | 104 ++++++ 5 files changed, 350 insertions(+), 299 deletions(-) create mode 100644 contrib/registry/polaris/polaris.go create mode 100644 contrib/registry/polaris/polaris_discovery.go rename contrib/registry/polaris/{polaris_registry_test.go => polaris_test.go} (100%) create mode 100644 contrib/registry/polaris/polaris_watcher.go diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go new file mode 100644 index 00000000000..f00ba678ca4 --- /dev/null +++ b/contrib/registry/polaris/polaris.go @@ -0,0 +1,204 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +// Package polaris implements service Registry and Discovery using polaris. +package polaris + +import ( + "fmt" + "strings" + "time" + + "github.com/polarismesh/polaris-go/api" + "github.com/polarismesh/polaris-go/pkg/config" + "github.com/polarismesh/polaris-go/pkg/model" + + "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/util/gconv" +) + +var ( + _ gsvc.Registrar = &Registry{} +) + +// _instanceIDSeparator Instance id Separator. +const _instanceIDSeparator = "-" + +type options struct { + // required, namespace in polaris + Namespace string + + // required, service access token + ServiceToken string + + // optional, protocol in polaris. Default value is nil, it means use protocol config in service + Protocol *string + + // service weight in polaris. Default value is 100, 0 <= weight <= 10000 + Weight int + + // service priority. Default value is 0. The smaller the value, the lower the priority + Priority int + + // To show service is healthy or not. Default value is True. + Healthy bool + + // Heartbeat enable .Not in polaris . Default value is True. + Heartbeat bool + + // To show service is isolate or not. Default value is False. + Isolate bool + + // TTL timeout. if node needs to use heartbeat to report,required. If not set,server will throw ErrorCode-400141 + TTL int + + // optional, Timeout for single query. Default value is global config + // Total is (1+RetryCount) * Timeout + Timeout time.Duration + + // optional, retry count. Default value is global config + RetryCount int +} + +// Option The option is a polaris option. +type Option func(o *options) + +// Registry is polaris registry. +type Registry struct { + opt options + provider api.ProviderAPI + consumer api.ConsumerAPI +} + +// WithNamespace with the Namespace option. +func WithNamespace(namespace string) Option { + return func(o *options) { o.Namespace = namespace } +} + +// WithServiceToken with ServiceToken option. +func WithServiceToken(serviceToken string) Option { + return func(o *options) { o.ServiceToken = serviceToken } +} + +// WithProtocol with the Protocol option. +func WithProtocol(protocol string) Option { + return func(o *options) { o.Protocol = &protocol } +} + +// WithWeight with the Weight option. +func WithWeight(weight int) Option { + return func(o *options) { o.Weight = weight } +} + +// WithHealthy with the Healthy option. +func WithHealthy(healthy bool) Option { + return func(o *options) { o.Healthy = healthy } +} + +// WithIsolate with the Isolate option. +func WithIsolate(isolate bool) Option { + return func(o *options) { o.Isolate = isolate } +} + +// WithTTL with the TTL option. +func WithTTL(TTL int) Option { + return func(o *options) { o.TTL = TTL } +} + +// WithTimeout the Timeout option. +func WithTimeout(timeout time.Duration) Option { + return func(o *options) { o.Timeout = timeout } +} + +// WithRetryCount with RetryCount option. +func WithRetryCount(retryCount int) Option { + return func(o *options) { o.RetryCount = retryCount } +} + +// WithHeartbeat with the Heartbeat option. +func WithHeartbeat(heartbeat bool) Option { + return func(o *options) { o.Heartbeat = heartbeat } +} + +// NewRegistry create a new registry. +func NewRegistry(provider api.ProviderAPI, consumer api.ConsumerAPI, opts ...Option) (r *Registry) { + op := options{ + Namespace: "default", + ServiceToken: "", + Protocol: nil, + Weight: 0, + Priority: 0, + Healthy: true, + Heartbeat: true, + Isolate: false, + TTL: 0, + Timeout: 0, + RetryCount: 0, + } + for _, option := range opts { + option(&op) + } + return &Registry{ + opt: op, + provider: provider, + consumer: consumer, + } +} + +// NewRegistryWithConfig new a registry with config. +func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Registry) { + provider, err := api.NewProviderAPIByConfig(conf) + if err != nil { + panic(err) + } + consumer, err := api.NewConsumerAPIByConfig(conf) + if err != nil { + panic(err) + } + return NewRegistry(provider, consumer, opts...) +} + +func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service { + serviceInstances := make([]*gsvc.Service, 0, len(instances)) + for _, instance := range instances { + if instance.IsHealthy() { + serviceInstances = append(serviceInstances, instanceToServiceInstance(instance)) + } + } + return serviceInstances +} + +func instanceToServiceInstance(instance model.Instance) *gsvc.Service { + metadata := instance.GetMetadata() + // Usually, it won't fail in goframe if register correctly + kind := "" + if k, ok := metadata["kind"]; ok { + kind = k + } + + name := "" + names := strings.Split(instance.GetService(), _instanceIDSeparator) + if names != nil && len(names) > 4 { + return &gsvc.Service{ + Prefix: names[0], + Deployment: names[1], + Namespace: names[2], + Name: names[3], + Version: metadata["version"], + Metadata: gconv.Map(metadata), + Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())}, + Separator: _instanceIDSeparator, + } + } + + return &gsvc.Service{ + Name: name, + Version: metadata["version"], + Metadata: gconv.Map(metadata), + Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, instance.GetHost(), instance.GetPort())}, + Separator: _instanceIDSeparator, + } +} diff --git a/contrib/registry/polaris/polaris_discovery.go b/contrib/registry/polaris/polaris_discovery.go new file mode 100644 index 00000000000..524e3d267a6 --- /dev/null +++ b/contrib/registry/polaris/polaris_discovery.go @@ -0,0 +1,42 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package polaris + +import ( + "context" + + "github.com/polarismesh/polaris-go/api" + "github.com/polarismesh/polaris-go/pkg/model" + + "github.com/gogf/gf/v2/net/gsvc" +) + +// Search returns the service instances in memory according to the service name. +func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { + in.Separator = _instanceIDSeparator + // get all instances + instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ + GetAllInstancesRequest: model.GetAllInstancesRequest{ + Service: in.Key(), + Namespace: r.opt.Namespace, + Timeout: &r.opt.Timeout, + RetryCount: &r.opt.RetryCount, + }, + }) + if err != nil { + return nil, err + } + + serviceInstances := instancesToServiceInstances(instancesResponse.GetInstances()) + + return serviceInstances, nil +} + +// Watch creates a watcher according to the service name. +func (r *Registry) Watch(ctx context.Context, serviceName string) (gsvc.Watcher, error) { + return newWatcher(ctx, r.opt.Namespace, serviceName, r.consumer) +} diff --git a/contrib/registry/polaris/polaris_registry.go b/contrib/registry/polaris/polaris_registry.go index e6fe66a50cf..fe9fbe97a97 100644 --- a/contrib/registry/polaris/polaris_registry.go +++ b/contrib/registry/polaris/polaris_registry.go @@ -4,12 +4,10 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -// Package polaris implements service Registry and Discovery using polaris. package polaris import ( "context" - "fmt" "net" "net/url" "strconv" @@ -17,7 +15,6 @@ import ( "time" "github.com/polarismesh/polaris-go/api" - "github.com/polarismesh/polaris-go/pkg/config" "github.com/polarismesh/polaris-go/pkg/model" "github.com/gogf/gf/v2/frame/g" @@ -25,147 +22,6 @@ import ( "github.com/gogf/gf/v2/util/gconv" ) -var ( - _ gsvc.Registrar = &Registry{} -) - -// _instanceIDSeparator Instance id Separator. -const _instanceIDSeparator = "-" - -type options struct { - // required, namespace in polaris - Namespace string - - // required, service access token - ServiceToken string - - // optional, protocol in polaris. Default value is nil, it means use protocol config in service - Protocol *string - - // service weight in polaris. Default value is 100, 0 <= weight <= 10000 - Weight int - - // service priority. Default value is 0. The smaller the value, the lower the priority - Priority int - - // To show service is healthy or not. Default value is True. - Healthy bool - - // Heartbeat enable .Not in polaris . Default value is True. - Heartbeat bool - - // To show service is isolate or not. Default value is False. - Isolate bool - - // TTL timeout. if node needs to use heartbeat to report,required. If not set,server will throw ErrorCode-400141 - TTL int - - // optional, Timeout for single query. Default value is global config - // Total is (1+RetryCount) * Timeout - Timeout time.Duration - - // optional, retry count. Default value is global config - RetryCount int -} - -// Option The option is a polaris option. -type Option func(o *options) - -// Registry is polaris registry. -type Registry struct { - opt options - provider api.ProviderAPI - consumer api.ConsumerAPI -} - -// WithNamespace with the Namespace option. -func WithNamespace(namespace string) Option { - return func(o *options) { o.Namespace = namespace } -} - -// WithServiceToken with ServiceToken option. -func WithServiceToken(serviceToken string) Option { - return func(o *options) { o.ServiceToken = serviceToken } -} - -// WithProtocol with the Protocol option. -func WithProtocol(protocol string) Option { - return func(o *options) { o.Protocol = &protocol } -} - -// WithWeight with the Weight option. -func WithWeight(weight int) Option { - return func(o *options) { o.Weight = weight } -} - -// WithHealthy with the Healthy option. -func WithHealthy(healthy bool) Option { - return func(o *options) { o.Healthy = healthy } -} - -// WithIsolate with the Isolate option. -func WithIsolate(isolate bool) Option { - return func(o *options) { o.Isolate = isolate } -} - -// WithTTL with the TTL option. -func WithTTL(TTL int) Option { - return func(o *options) { o.TTL = TTL } -} - -// WithTimeout the Timeout option. -func WithTimeout(timeout time.Duration) Option { - return func(o *options) { o.Timeout = timeout } -} - -// WithRetryCount with RetryCount option. -func WithRetryCount(retryCount int) Option { - return func(o *options) { o.RetryCount = retryCount } -} - -// WithHeartbeat with the Heartbeat option. -func WithHeartbeat(heartbeat bool) Option { - return func(o *options) { o.Heartbeat = heartbeat } -} - -// NewRegistry 创建一个注册服务 -func NewRegistry(provider api.ProviderAPI, consumer api.ConsumerAPI, opts ...Option) (r *Registry) { - op := options{ - Namespace: "default", - ServiceToken: "", - Protocol: nil, - Weight: 0, - Priority: 0, - Healthy: true, - Heartbeat: true, - Isolate: false, - TTL: 0, - Timeout: 0, - RetryCount: 0, - } - for _, option := range opts { - option(&op) - } - return &Registry{ - opt: op, - provider: provider, - consumer: consumer, - } -} - -// NewRegistryWithConfig new a registry with config. -func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Registry) { - provider, err := api.NewProviderAPIByConfig(conf) - if err != nil { - panic(err) - } - consumer, err := api.NewConsumerAPIByConfig(conf) - if err != nil { - panic(err) - } - return NewRegistry(provider, consumer, opts...) -} - // Register the registration. func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) error { ids := make([]string, 0, len(serviceInstance.Endpoints)) @@ -311,158 +167,3 @@ func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service } return nil } - -// Search returns the service instances in memory according to the service name. -func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { - in.Separator = _instanceIDSeparator - // get all instances - instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ - GetAllInstancesRequest: model.GetAllInstancesRequest{ - Service: in.Key(), - Namespace: r.opt.Namespace, - Timeout: &r.opt.Timeout, - RetryCount: &r.opt.RetryCount, - }, - }) - if err != nil { - return nil, err - } - - serviceInstances := instancesToServiceInstances(instancesResponse.GetInstances()) - - return serviceInstances, nil -} - -// Watch creates a watcher according to the service name. -func (r *Registry) Watch(ctx context.Context, serviceName string) (gsvc.Watcher, error) { - return newWatcher(ctx, r.opt.Namespace, serviceName, r.consumer) -} - -// Watcher is a service watcher. -type Watcher struct { - ServiceName string - Namespace string - Ctx context.Context - Cancel context.CancelFunc - Channel <-chan model.SubScribeEvent - ServiceInstances []*gsvc.Service -} - -func newWatcher(ctx context.Context, namespace string, serviceName string, consumer api.ConsumerAPI) (*Watcher, error) { - watchServiceResponse, err := consumer.WatchService(&api.WatchServiceRequest{ - WatchServiceRequest: model.WatchServiceRequest{ - Key: model.ServiceKey{ - Namespace: namespace, - Service: serviceName, - }, - }, - }) - if err != nil { - return nil, err - } - - w := &Watcher{ - Namespace: namespace, - ServiceName: serviceName, - Channel: watchServiceResponse.EventChannel, - ServiceInstances: instancesToServiceInstances(watchServiceResponse.GetAllInstancesResp.GetInstances()), - } - w.Ctx, w.Cancel = context.WithCancel(ctx) - return w, nil -} - -// Proceed returns services in the following two cases: -// 1.the first time to watch and the service instance list is not empty. -// 2.any service instance changes found. -// if the above two conditions are not met, it will block until the context deadline is exceeded or canceled -func (w *Watcher) Proceed() ([]*gsvc.Service, error) { - select { - case <-w.Ctx.Done(): - return nil, w.Ctx.Err() - case event := <-w.Channel: - if event.GetSubScribeEventType() == model.EventInstance { - // these are always true, but we need to check it to make sure EventType not change - if instanceEvent, ok := event.(*model.InstanceEvent); ok { - // handle DeleteEvent - if instanceEvent.DeleteEvent != nil { - for _, instance := range instanceEvent.DeleteEvent.Instances { - for i, serviceInstance := range w.ServiceInstances { - if serviceInstance.ID == instance.GetId() { - // remove equal - if len(w.ServiceInstances) <= 1 { - w.ServiceInstances = w.ServiceInstances[0:0] - continue - } - w.ServiceInstances = append(w.ServiceInstances[:i], w.ServiceInstances[i+1:]...) - } - } - } - } - // handle UpdateEvent - if instanceEvent.UpdateEvent != nil { - for i, serviceInstance := range w.ServiceInstances { - for _, update := range instanceEvent.UpdateEvent.UpdateList { - if serviceInstance.ID == update.Before.GetId() { - w.ServiceInstances[i] = instanceToServiceInstance(update.After) - } - } - } - } - // handle AddEvent - if instanceEvent.AddEvent != nil { - w.ServiceInstances = append(w.ServiceInstances, instancesToServiceInstances(instanceEvent.AddEvent.Instances)...) - } - } - return w.ServiceInstances, nil - } - } - return w.ServiceInstances, nil -} - -// Close the watcher. -func (w *Watcher) Close() error { - w.Cancel() - return nil -} - -func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service { - serviceInstances := make([]*gsvc.Service, 0, len(instances)) - for _, instance := range instances { - if instance.IsHealthy() { - serviceInstances = append(serviceInstances, instanceToServiceInstance(instance)) - } - } - return serviceInstances -} - -func instanceToServiceInstance(instance model.Instance) *gsvc.Service { - metadata := instance.GetMetadata() - // Usually, it won't fail in goframe if register correctly - kind := "" - if k, ok := metadata["kind"]; ok { - kind = k - } - - name := "" - names := strings.Split(instance.GetService(), _instanceIDSeparator) - if names != nil && len(names) > 4 { - return &gsvc.Service{ - Prefix: names[0], - Deployment: names[1], - Namespace: names[2], - Name: names[3], - Version: metadata["version"], - Metadata: gconv.Map(metadata), - Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())}, - Separator: _instanceIDSeparator, - } - } - - return &gsvc.Service{ - Name: name, - Version: metadata["version"], - Metadata: gconv.Map(metadata), - Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, instance.GetHost(), instance.GetPort())}, - Separator: _instanceIDSeparator, - } -} diff --git a/contrib/registry/polaris/polaris_registry_test.go b/contrib/registry/polaris/polaris_test.go similarity index 100% rename from contrib/registry/polaris/polaris_registry_test.go rename to contrib/registry/polaris/polaris_test.go diff --git a/contrib/registry/polaris/polaris_watcher.go b/contrib/registry/polaris/polaris_watcher.go new file mode 100644 index 00000000000..053f657bfa5 --- /dev/null +++ b/contrib/registry/polaris/polaris_watcher.go @@ -0,0 +1,104 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package polaris + +import ( + "context" + + "github.com/polarismesh/polaris-go/api" + "github.com/polarismesh/polaris-go/pkg/model" + + "github.com/gogf/gf/v2/net/gsvc" +) + +// Watcher is a service watcher. +type Watcher struct { + ServiceName string + Namespace string + Ctx context.Context + Cancel context.CancelFunc + Channel <-chan model.SubScribeEvent + ServiceInstances []*gsvc.Service +} + +func newWatcher(ctx context.Context, namespace string, serviceName string, consumer api.ConsumerAPI) (*Watcher, error) { + watchServiceResponse, err := consumer.WatchService(&api.WatchServiceRequest{ + WatchServiceRequest: model.WatchServiceRequest{ + Key: model.ServiceKey{ + Namespace: namespace, + Service: serviceName, + }, + }, + }) + if err != nil { + return nil, err + } + + w := &Watcher{ + Namespace: namespace, + ServiceName: serviceName, + Channel: watchServiceResponse.EventChannel, + ServiceInstances: instancesToServiceInstances(watchServiceResponse.GetAllInstancesResp.GetInstances()), + } + w.Ctx, w.Cancel = context.WithCancel(ctx) + return w, nil +} + +// Proceed returns services in the following two cases: +// 1.the first time to watch and the service instance list is not empty. +// 2.any service instance changes found. +// if the above two conditions are not met, it will block until the context deadline is exceeded or canceled +func (w *Watcher) Proceed() ([]*gsvc.Service, error) { + select { + case <-w.Ctx.Done(): + return nil, w.Ctx.Err() + case event := <-w.Channel: + if event.GetSubScribeEventType() == model.EventInstance { + // these are always true, but we need to check it to make sure EventType not change + instanceEvent, ok := event.(*model.InstanceEvent) + if !ok { + return w.ServiceInstances, nil + } + // handle DeleteEvent + if instanceEvent.DeleteEvent != nil { + for _, instance := range instanceEvent.DeleteEvent.Instances { + for i, serviceInstance := range w.ServiceInstances { + if serviceInstance.ID == instance.GetId() { + // remove equal + if len(w.ServiceInstances) <= 1 { + w.ServiceInstances = w.ServiceInstances[0:0] + continue + } + w.ServiceInstances = append(w.ServiceInstances[:i], w.ServiceInstances[i+1:]...) + } + } + } + } + // handle UpdateEvent + if instanceEvent.UpdateEvent != nil { + for i, serviceInstance := range w.ServiceInstances { + for _, update := range instanceEvent.UpdateEvent.UpdateList { + if serviceInstance.ID == update.Before.GetId() { + w.ServiceInstances[i] = instanceToServiceInstance(update.After) + } + } + } + } + // handle AddEvent + if instanceEvent.AddEvent != nil { + w.ServiceInstances = append(w.ServiceInstances, instancesToServiceInstances(instanceEvent.AddEvent.Instances)...) + } + } + } + return w.ServiceInstances, nil +} + +// Close the watcher. +func (w *Watcher) Close() error { + w.Cancel() + return nil +} From 81f2c9890e58ddc536c61883ecf1c98a8564b3e8 Mon Sep 17 00:00:00 2001 From: houseme Date: Fri, 13 May 2022 00:42:48 +0800 Subject: [PATCH 62/70] up golangci-lint config file --- .golangci.yml | 993 +++----------------------------------------------- 1 file changed, 55 insertions(+), 938 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c5481fc9588..cb39e80535f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,949 +1,66 @@ -# This file contains all available configuration options -# with their default values. - -# options for analysis running +## This file contains all available configuration options +## with their default values. +# +# See https://github.com/golangci/golangci-lint#config-file run: - # default concurrency is a available CPU number - concurrency: 4 - - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 5m - - # exit code when at least one issue was found, default is 1 - issues-exit-code: 1 - - # include test files or not, default is true - tests: false - - # list of build tags, all linters use it. Default is empty list. - build-tags: -# - mytag - - # which dirs to skip: issues from them won't be reported; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but default dirs are skipped independently - # from this option's value (see skip-dirs-use-default). - # "/" will be replaced by current OS file path separator to properly work - # on Windows. - skip-dirs: - - .example - - .test - - # default is true. Enables skipping of directories: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ - skip-dirs-use-default: true - - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. - # "/" will be replaced by current OS file path separator to properly work - # on Windows. - skip-files: - - ".*_test\\.go$" - - ".*_packed\\.go$" - - # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": - # If invoked with -mod=readonly, the go command is disallowed from the implicit - # automatic updating of go.mod described above. Instead, it fails when any changes - # to go.mod are needed. This setting is most useful to check that go.mod does - # not need updates, such as in a continuous integration and testing system. - # If invoked with -mod=vendor, the go command assumes that the vendor - # directory holds the correct copies of dependencies and ignores - # the dependency descriptions in go.mod. - #modules-download-mode: release|readonly|vendor - - # Allow multiple parallel golangci-lint instances running. - # If false (default) - golangci-lint acquires file lock on start. - allow-parallel-runners: true - - -# output configuration options -output: - # colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions - # default is "colored-line-number" - format: colored-line-number - - # print lines of code with issue, default is true - print-issued-lines: true - - # print linter name in the end of issue text, default is true - print-linter-name: true - - # make issues output unique by line, default is true - uniq-by-line: true - - # add a prefix to the output file references; default is no prefix - path-prefix: "" - - # sorts results by: filepath, line and column - sort-results: true - - -# all available settings of specific linters -linters-settings: - bidichk: - # The following configurations check for all mentioned invisible unicode - # runes. It can be omitted because all runes are enabled by default. - left-to-right-embedding: true - right-to-left-embedding: true - pop-directional-formatting: true - left-to-right-override: true - right-to-left-override: true - left-to-right-isolate: true - right-to-left-isolate: true - first-strong-isolate: true - pop-directional-isolate: true - - cyclop: - # the maximal code complexity to report - max-complexity: 50 - # the maximal average package complexity. If it's higher than 0.0 (float) the check is enabled (default 0.0) - package-average: 0.0 - # should ignore tests (default false) - skip-tests: false - - dogsled: - # checks assignments with too many blank identifiers; default is 2 - max-blank-identifiers: 2 - - dupl: - # tokens count to trigger issue, 150 by default - threshold: 100 - - errcheck: - # report about not checking of errors in type assertions: `a := b.(MyStruct)`; - # default is false: such cases aren't reported by default. - check-type-assertions: false - - # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; - # default is false: such cases aren't reported by default. - check-blank: false - - # [deprecated] comma-separated list of pairs of the form pkg:regex - # the regex is used to ignore names within pkg. (default "fmt:.*"). - # see https://github.com/kisielk/errcheck#the-deprecated-method for details - #ignore: fmt:.*,io/ioutil:^Read.* - - # [deprecated] use exclude-functions instead. - # path to a file containing a list of functions to exclude from checking - # see https://github.com/kisielk/errcheck#excluding-functions for details - # exclude: /path/to/file.txt - - # list of functions to exclude from checking, where each entry is a single function to exclude. - # see https://github.com/kisielk/errcheck#excluding-functions for details - exclude-functions: -# - io/ioutil.ReadFile -# - io.Copy(*bytes.Buffer) -# - io.Copy(os.Stdout) - - errorlint: - # Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats - errorf: true - # Check for plain type assertions and type switches - asserts: true - # Check for plain error comparisons - comparison: true - - exhaustive: - # check switch statements in generated files also - check-generated: false - # presence of "default" case in switch statements satisfies exhaustiveness, - # even if all enum members are not listed - default-signifies-exhaustive: false - # enum members matching the supplied regex do not have to be listed in - # switch statements to satisfy exhaustiveness - ignore-enum-members: "" - # consider enums only in package scopes, not in inner scopes - package-scope-only: false - - exhaustivestruct: - # Struct Patterns is list of expressions to match struct packages and names - # The struct packages have the form example.com/package.ExampleStruct - # The matching patterns can use matching syntax from https://pkg.go.dev/path#Match - # If this list is empty, all structs are tested. - struct-patterns: -# - '*.Test' -# - 'example.com/package.ExampleStruct' -# - '*.Test2' -# - '*.Embedded' -# - '*.External' - - forbidigo: - # Forbid the following identifiers (identifiers are written using regexp): - forbid: -# - ^print.*$ -# - 'fmt\.Print.*' -# - fmt.Println.* # too much log noise -# - ginkgo\\.F.* # these are used just for local development - # Exclude godoc examples from forbidigo checks. Default is true. - exclude_godoc_examples: false - - funlen: - lines: 150 - statements: 50 - - gci: - # put imports beginning with prefix after 3rd-party packages; - # only support one prefix - # if not set, use goimports.local-prefixes - local-prefixes: github.com/gogf/gf - - gocognit: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 50 - - goconst: - # minimal length of string constant, 3 by default - min-len: 3 - # minimum occurrences of constant string count to trigger issue, 3 by default - min-occurrences: 3 - # ignore test files, false by default - ignore-tests: true - # look for existing constants matching the values, true by default - match-constant: true - # search also for duplicated numbers, false by default - numbers: false - # minimum value, only works with goconst.numbers, 3 by default - min: 3 - # maximum value, only works with goconst.numbers, 3 by default - max: 3 - # ignore when constant is not used as function argument, true by default - ignore-calls: true - - gocritic: - # Which checks should be enabled; can't be combined with 'disabled-checks'; - # See https://go-critic.github.io/overview#checks-overview - # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` - # By default list of stable checks is used. - enabled-checks: - - nestingReduce - - unnamedresult - - ruleguard - - truncateCmp - - # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty - disabled-checks: - - regexpMust - - ifElseChain - - exitAfterDefer - - # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. - # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". - enabled-tags: - - performance - disabled-tags: - - experimental - - # Settings passed to gocritic. - # The settings key is the name of a supported gocritic checker. - # The list of supported checkers can be find in https://go-critic.github.io/overview. - settings: - captLocal: # must be valid enabled check name - # whether to restrict checker to params only (default true) - paramsOnly: true - elseif: - # whether to skip balanced if-else pairs (default true) - skipBalanced: true - hugeParam: - # size in bytes that makes the warning trigger (default 80) - sizeThreshold: 80 - nestingReduce: - # min number of statements inside a branch to trigger a warning (default 5) - bodyWidth: 5 - rangeExprCopy: - # size in bytes that makes the warning trigger (default 512) - sizeThreshold: 512 - # whether to check test functions (default true) - skipTestFuncs: true - rangeValCopy: - # size in bytes that makes the warning trigger (default 128) - sizeThreshold: 32 - # whether to check test functions (default true) - skipTestFuncs: true - ruleguard: - # Enable debug to identify which 'Where' condition was rejected. - # The value of the parameter is the name of a function in a ruleguard file. - # - # When a rule is evaluated: - # If: - # The Match() clause is accepted; and - # One of the conditions in the Where() clause is rejected, - # Then: - # ruleguard prints the specific Where() condition that was rejected. - # - # The flag is passed to the ruleguard 'debug-group' argument. - debug: 'emptyDecl' - # Deprecated, use 'failOn' param. - # If set to true, identical to failOn='all', otherwise failOn='' - failOnError: false - # Determines the behavior when an error occurs while parsing ruleguard files. - # If flag is not set, log error and skip rule files that contain an error. - # If flag is set, the value must be a comma-separated list of error conditions. - # - 'all': fail on all errors. - # - 'import': ruleguard rule imports a package that cannot be found. - # - 'dsl': gorule file does not comply with the ruleguard DSL. - failOn: dsl - # Comma-separated list of file paths containing ruleguard rules. - # If a path is relative, it is relative to the directory where the golangci-lint command is executed. - # The special '${configDir}' variable is substituted with the absolute directory containing the golangci config file. - # Glob patterns such as 'rules-*.go' may be specified. - rules: '' #${configDir}/ruleguard/rules-*.go,${configDir}/myrule1.go' - #tooManyResultsChecker: - # maximum number of results (default 5) - #maxResults: 10 - truncateCmp: - # whether to skip int/uint/uintptr types (default true) - skipArchDependent: true - underef: - # whether to skip (*x).method() calls where x is a pointer receiver (default true) - skipRecvDeref: true - unnamedResult: - # whether to check exported functions - checkExported: true - - gocyclo: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 30 - - godot: - # comments to be checked: `declarations`, `toplevel`, or `all` - scope: declarations - # list of regexps for excluding particular comment lines from check - exclude: - # example: exclude comments which contain numbers - # - '[0-9]+' - # check that each sentence starts with a capital letter - capital: false - - godox: - # report any comments starting with keywords, this is useful for TODO or FIXME comments that - # might be left in the code accidentally and should be resolved before merging - keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting - #- NOTE - - BUG - - FIXME - - OPTIMIZE # marks code that should be optimized before merging - - HACK # marks hack-arounds that should be removed before merging - - gofmt: - # simplify code: gofmt with `-s` option, true by default - simplify: true - - gofumpt: - # Select the Go version to target. The default is `1.15`. - lang-version: "1.16" - - # Choose whether or not to use the extra rules that are disabled - # by default - extra-rules: false - - goheader: - values: - const: - # define here const type values in format k:v, for example: - # COMPANY: MY COMPANY - regexp: - # define here regexp type values, for example - # AUTHOR: .*@mycompany\.com - template: # |- - # put here copyright header template for source code files, for example: - # Note: {{ YEAR }} is a builtin value that returns the year relative to the current machine time. - # - # {{ AUTHOR }} {{ COMPANY }} {{ YEAR }} - # SPDX-License-Identifier: Apache-2.0 - - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at: - - # http://www.apache.org/licenses/LICENSE-2.0 - - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - template-path: - # also as alternative of directive 'template' you may put the path to file with the template source - - goimports: - # put imports beginning with prefix after 3rd-party packages; - # it's a comma-separated list of prefixes - local-prefixes: github.com/gogf/gf - - golint: - # minimal confidence for issues, default is 0.8 - min-confidence: 0.9 - - gomnd: - settings: - mnd: - # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. - checks: argument,case,condition,operation,return,assign - # ignored-numbers: 1000 - # ignored-files: magic_.*.go - # ignored-functions: math.* - - gomoddirectives: - # Allow local `replace` directives. Default is false. - replace-local: false - # List of allowed `replace` directives. Default is empty. - replace-allow-list: - - launchpad.net/gocheck - - github.com/coreos/etcd - - google.golang.org/grpc - - gitlab.jntmedia.cn/lanren/core - # Allow to not explain why the version has been retracted in the `retract` directives. Default is false. - retract-allow-no-explanation: false - # Forbid the use of the `exclude` directives. Default is false. - exclude-forbidden: false - - gomodguard: - allowed: - modules: # List of allowed modules - # - gopkg.in/yaml.v2 - - gorm.io/gorm - - gorm.io/driver/mysql - - k8s.io/klog - domains: # List of allowed module domains - # - golang.org - - google.golang.org - - gopkg.in - - golang.org - - github.com - - go.uber.org - blocked: - modules: # List of blocked modules - # - github.com/uudashr/go-module: # Blocked module - # recommendations: # Recommended modules that should be used instead (Optional) - # - golang.org/x/mod - # reason: "`mod` is the official go.mod parser library." # Reason why the recommended module should be used (Optional) - versions: # List of blocked module version constraints - # - github.com/mitchellh/go-homedir: # Blocked module with version constraint - # version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons - # reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional) - local_replace_directives: false # Set to true to raise lint issues for packages that are loaded from a local path via replace directive - - gosec: - # To select a subset of rules to run. - # Available rules: https://github.com/securego/gosec#available-rules - includes: - - G401 - - G306 - - G101 - # To specify a set of rules to explicitly exclude. - # Available rules: https://github.com/securego/gosec#available-rules - excludes: - - G204 - # Exclude generated files - exclude-generated: true - # Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high. - severity: "low" - # Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high. - confidence: "low" - # To specify the configuration of rules. - # The configuration of rules is not fully documented by gosec: - # https://github.com/securego/gosec#configuration - # https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/rules/rulelist.go#L60-L102 - config: - G306: "0600" - G101: - pattern: "(?i)example" - ignore_entropy: false - entropy_threshold: "80.0" - per_char_threshold: "3.0" - truncate: "32" - - gosimple: - # Select the Go version to target. The default is '1.13'. - go: "1.16" - # https://staticcheck.io/docs/options#checks - checks: [ "all" ] - - govet: - # report about shadowed variables - check-shadowing: true - - # settings per analyzer - settings: - printf: # analyzer name, run `go tool vet help` to see all analyzers - funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - - # enable or disable analyzers by name - # run `go tool vet help` to see all analyzers - enable: - - atomicalign - enable-all: false - disable: - - shadow - disable-all: false - - depguard: - list-type: blacklist - include-go-root: false - packages: - - github.com/sirupsen/logrus - packages-with-error-message: - # specify an error message to output when a blacklisted package is used - - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" - - ifshort: - # Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax. - # Has higher priority than max-decl-chars. - max-decl-lines: 1 - # Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax. - max-decl-chars: 30 - - importas: - # if set to `true`, force to use alias. - no-unaliased: true - # List of aliases - alias: - # using `servingv1` alias for `knative.dev/serving/pkg/apis/serving/v1` package - - pkg: knative.dev/serving/pkg/apis/serving/v1 - alias: servingv1 - # using `autoscalingv1alpha1` alias for `knative.dev/serving/pkg/apis/autoscaling/v1alpha1` package - - pkg: knative.dev/serving/pkg/apis/autoscaling/v1alpha1 - alias: autoscalingv1alpha1 - # You can specify the package path by regular expression, - # and alias by regular expression expansion syntax like below. - # see https://github.com/julz/importas#use-regular-expression for details - - pkg: knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+) - alias: $1$2 - - ireturn: - # ireturn allows using `allow` and `reject` settings at the same time. - # Both settings are lists of the keywords and regular expressions matched to interface or package names. - # keywords: - # - `empty` for `interface{}` - # - `error` for errors - # - `stdlib` for standard library - # - `anon` for anonymous interfaces - - # By default, it allows using errors, empty interfaces, anonymous interfaces, - # and interfaces provided by the standard library. - allow: - - anon - - error - - empty - - stdlib - # You can specify idiomatic endings for interface - - (or|er)$ - - # Reject patterns -# reject: -# - github.com\/user\/package\/v4\.Type - - lll: - # max line length, lines longer will be reported. Default is 120. - # '\t' is counted as 1 character by default, and can be changed with the tab-width option - line-length: 240 - # tab width in spaces. Default to 1. - tab-width: 4 - - makezero: - # Allow only slices initialized with a length of zero. Default is false. - always: false - - maligned: - # print struct with more effective memory layout or not, false by default - suggest-new: true - - misspell: - # Correct spellings using locale preferences for US or UK. - # Default is to use a neutral variety of English. - # Setting locale to US will correct the British spelling of 'colour' to 'color'. - locale: US - ignore-words: - - someword - - nakedret: - # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 - max-func-lines: 30 - - nestif: - # minimal complexity of if statements to report, 5 by default - min-complexity: 4 - - nilnil: - # By default, nilnil checks all returned types below. - checked-types: - - ptr - - func - - iface - - map - - chan - - nlreturn: - # size of the block (including return statement that is still "OK") - # so no return split required. - block-size: 1 - - nolintlint: - # Disable to ensure that all nolint directives actually have an effect. Default is true. - allow-unused: true - # Disable to ensure that nolint directives don't have a leading space. Default is true. - allow-leading-space: true - # Exclude following linters from requiring an explanation. Default is []. - allow-no-explanation: [ ] - # Enable to require an explanation of nonzero length after each nolint directive. Default is false. - require-explanation: false - # Enable to require nolint directives to mention the specific linter being suppressed. Default is false. - require-specific: true - - prealloc: - # XXX: we don't recommend using this linter before doing performance profiling. - # For most programs usage of prealloc will be a premature optimization. - - # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. - # True by default. - simple: true - range-loops: true # Report preallocation suggestions on range loops, true by default - for-loops: false # Report preallocation suggestions on for loops, false by default - - promlinter: - # Promlinter cannot infer all metrics name in static analysis. - # Enable strict mode will also include the errors caused by failing to parse the args. - strict: false - # Please refer to https://github.com/yeya24/promlinter#usage for detailed usage. - disabled-linters: - # - "Help" - # - "MetricUnits" - # - "Counter" - # - "HistogramSummaryReserved" - # - "MetricTypeInName" - # - "ReservedChars" - # - "CamelCase" - # - "lintUnitAbbreviations" - - predeclared: - # comma-separated list of predeclared identifiers to not report on - ignore: "" - # include method names and field names (i.e., qualified names) in checks - q: false - - rowserrcheck: - packages: - - github.com/jmoiron/sqlx - - revive: - # see https://github.com/mgechev/revive#available-rules for details. - ignore-generated-header: true - severity: warning - rules: - - name: indent-error-flow - severity: warning - - name: add-constant - severity: warning - arguments: - - maxLitCount: "3" - allowStrs: '""' - allowInts: "0,1,2" - allowFloats: "0.0,0.,1.0,1.,2.0,2." - - staticcheck: - # Select the Go version to target. The default is '1.13'. - go: "1.16" - # https://staticcheck.io/docs/options#checks - checks: [ "all" ] - - stylecheck: - # Select the Go version to target. The default is '1.13'. - go: "1.16" - # https://staticcheck.io/docs/options#checks - checks: [ "all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022" ] - # https://staticcheck.io/docs/options#dot_import_whitelist - dot-import-whitelist: - - fmt - # https://staticcheck.io/docs/options#initialisms - initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS" ] - # https://staticcheck.io/docs/options#http_status_code_whitelist - http-status-code-whitelist: [ "200", "400", "404", "500" ] - - tagliatelle: - # check the struck tag name case - case: - # use the struct field name to check the name of the struct tag - use-field-name: true - rules: - # any struct tag type can be used. - # support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower` - json: camel - yaml: camel - xml: camel - bson: camel - avro: snake - mapstructure: kebab - - testpackage: - # regexp pattern to skip files - skip-regexp: (export|internal)_test\.go - - thelper: - # The following configurations enable all checks. It can be omitted because all checks are enabled by default. - # You can enable only required checks deleting unnecessary checks. - test: - first: true - name: true - begin: true - benchmark: - first: true - name: true - begin: true - tb: - first: true - name: true - begin: true - - tenv: - # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures. - # By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked. - all: false - - unparam: - # Inspect exported functions, default is false. Set to true if no external program/library imports your code. - # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: - # if it's called for subdir of a project it can't find external interfaces. All text editor integrations - # with golangci-lint call it on a directory with the changed file. - check-exported: false - - unused: - # Select the Go version to target. The default is '1.13'. - go: "1.16" - - varnamelen: - # The longest distance, in source lines, that is being considered a "small scope." (defaults to 5) - # Variables used in at most this many lines will be ignored. - max-distance: 5 - # The minimum length of a variable's name that is considered "long." (defaults to 3) - # Variable names that are at least this long will be ignored. - min-name-length: 1 - # Check method receiver names. (defaults to false) - check-receiver: false - # Check named return values. (defaults to false) - check-return: false - # Ignore "ok" variables that hold the bool return value of a type assertion. (defaults to false) - ignore-type-assert-ok: false - # Ignore "ok" variables that hold the bool return value of a map index. (defaults to false) - ignore-map-index-ok: false - # Ignore "ok" variables that hold the bool return value of a channel receive. (defaults to false) - ignore-chan-recv-ok: false - # Optional list of variable names that should be ignored completely. (defaults to empty list) - ignore-names: - - err - # Optional list of variable declarations that should be ignored completely. (defaults to empty list) - # Entries must be in the form of " " or " *". - ignore-decls: - - c echo.Context - - t testing.T - - f *foo.Bar - - e error - - i int - - whitespace: - multi-if: false # Enforces newlines (or comments) after every multi-line if statement - multi-func: false # Enforces newlines (or comments) after every multi-line function signature - - wrapcheck: - # An array of strings that specify substrings of signatures to ignore. - # If this set, it will override the default set of ignored signatures. - # See https://github.com/tomarrell/wrapcheck#configuration for more information. - ignoreSigs: - - .Errorf( - - errors.New( - - errors.Unwrap( - - .Wrap( - - .Wrapf( - - .WithMessage( - - .WithMessagef( - - .WithStack( - ignorePackageGlobs: - - encoding/* - - github.com/pkg/* - - wsl: - # See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for - # documentation of available settings. These are the defaults for - # `golangci-lint`. - allow-assign-and-anything: false - allow-assign-and-call: true - allow-cuddle-declarations: false - allow-multiline-assign: true - allow-separated-leading-comment: false - allow-trailing-comment: false - force-case-trailing-whitespace: 0 - force-err-cuddling: false - force-short-decl-cuddling: false - strict-append: true - - # The custom section can be used to define linter plugins to be loaded at runtime. - # See README doc for more info. - # custom: - # Each custom linter should have a unique name. - # example: - # The path to the plugin *.so. Can be absolute or local. Required for each custom linter - # path: /path/to/example.so - # The description of the linter. Optional, just for documentation purposes. - # description: This is an example usage of a plugin linter. - # Intended to point to the repo location of the linter. Optional, just for documentation purposes. - # original-url: github.com/golangci/example-linter + issues-exit-code: 1 #Default + tests: true #Default linters: - #disable-all: true - #enable: - # - megacheck - # - govet - enable-all: true - disable: - - maligned - - prealloc - #- tagliatelle - #- wrapcheck - #- forcetypeassert - - goerr113 - - gomnd - - wsl - - testpackage - - gochecknoglobals - - interfacer - - maligned - - scopelint - - gocritic + # Disable everything by default so upgrades to not include new "default + # enabled" linters. + disable-all: true + # Specifically enable linters we want to use. + enable: + - deadcode + - errcheck + - gofmt + - goimports + - gosimple + - govet + - godot + - ineffassign + - misspell + - revive + - staticcheck + - structcheck - typecheck -# presets: -# - bugs -# - unused - fast: false + - unused + - varcheck issues: - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` - exclude: - - abcdef - - tools/.* - - test/.* - - third_party/.* - - # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: - # Exclude some linters from running on tests files. - - linters: - - revive - path: (log/.*)\.go - - linters: - - wrapcheck - path: (cmd/.*|pkg/.*)\.go - - linters: - - typecheck - path: (pkg/storage/.*)\.go - - - path: (cmd/.*|test/.*|tools/.*)\.go + # helpers in tests often (rightfully) pass a *testing.T as their first argument + - path: _test\.go + text: "context.Context should be the first parameter of a function" linters: - - forbidigo - - path: (cmd/[a-z]*/.*|store/.*)\.go - linters: - - dupl - - linters: - - gocritic - text: (hugeParam:|rangeValCopy:) - - - path: (cmd/[a-z]*/.*)\.go - linters: - - lll - - - path: (validator/.*|code/.*|validator/.*) + - revive + # Yes, they are, but it's okay in a test + - path: _test\.go + text: "exported func.*returns unexported type.*which can be annoying to use" linters: - - gochecknoinits - - path: (pkg/app/.*)\.go - linters: - - gocyclo - - errcheck - - dupl - - gosec - - # Exclude known linters from partially hard-vendored code, - # which is impossible to exclude via "nolint" comments. - - path: internal/hmac/ - text: "weak cryptographic primitive" - linters: - - gosec - - # Exclude some staticcheck messages - - linters: - - staticcheck - text: "SA9003:" - - # Exclude lll issues for long lines with go:generate - - linters: - - lll - source: "^//go:generate " - - # Independently from option `exclude` we use default exclude patterns, - # it can be disabled by this option. To list all - # excluded by default patterns execute `golangci-lint run --help`. - # Default value for this option is true. - exclude-use-default: false - - # The default value is false. If set to true exclude and exclude-rules - # regular expressions become case sensitive. - exclude-case-sensitive: false - - # The list of ids of default excludes to include or disable. By default it's empty. - include: - - EXC0002 # disable excluding of issues about comments from golint + - revive - # Maximum issues count per one linter. Set to 0 to disable. Default is 50. - max-issues-per-linter: 0 - - # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. - max-same-issues: 0 - - # Show only new issues: if there are unstaged changes or untracked files, - # only those changes are analyzed, else only changes in HEAD~ are analyzed. - # It's a super-useful option for integration of golangci-lint into existing - # large codebase. It's not practical to fix all existing issues at the moment - # of integration: much better don't allow issues in new code. - # Default is false. - new: false - - # Show only new issues created after git revision `REV` - new-from-rev: REV - - # Show only new issues created in git patch with set file path. - # new-from-patch: path/to/patch/file - - # Fix found issues (if it's supported by the linter) - fix: true - -severity: - # Default value is empty string. - # Set the default severity for issues. If severity rules are defined and the issues - # do not match or no severity is provided to the rule this will be the default - # severity applied. Severities should match the supported severity names of the - # selected out format. - # - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity - # - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#severity - # - GitHub: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message - default-severity: error - - # The default value is false. - # If set to true severity-rules regular expressions become case sensitive. - case-sensitive: false - - # Default value is empty list. - # When a list of severity rules are provided, severity information will be added to lint - # issues. Severity rules have the same filtering capability as exclude rules except you - # are allowed to specify one matcher per severity rule. - # Only affects out formats that support setting severity information. - rules: - - linters: - - dupl - severity: info +linters-settings: + misspell: + locale: US + ignore-words: + - cancelled + goimports: + local-prefixes: github.com/gogf/gf + godot: + # Comments to be checked: `declarations`, `toplevel`, or `all`. + # Default: declarations + scope: toplevel + exclude: + # Exclude sentence fragments for lists. + - '^[ ]*[-•]' + # Exclude sentences prefixing a list. + - ':$' + # Check that each sentence ends with a period. + # Default: true + period: false + # Check that each sentence starts with a capital letter. + # Default: false + capital: false \ No newline at end of file From 3fb4256514fda3c24d64df8b8857172e39124af1 Mon Sep 17 00:00:00 2001 From: houseme Date: Fri, 13 May 2022 19:34:14 +0800 Subject: [PATCH 63/70] feat:add readme.md --- contrib/registry/etcd/etcd_registry.go | 2 +- contrib/registry/polaris/README.MD | 94 +++++++++++++++++++ contrib/registry/polaris/README_ZH.MD | 93 ++++++++++++++++++ contrib/registry/polaris/polaris.go | 15 +-- contrib/registry/polaris/polaris_discovery.go | 2 +- contrib/registry/polaris/polaris_registry.go | 35 ++++--- contrib/registry/polaris/polaris_test.go | 12 +-- net/ghttp/ghttp_server_registry.go | 4 +- net/gsvc/gsvc.go | 1 + net/gsvc/gsvc_search.go | 17 ++-- net/gsvc/gsvc_service.go | 34 ++++--- text/gstr/gstr_convert.go | 10 +- 12 files changed, 254 insertions(+), 65 deletions(-) create mode 100644 contrib/registry/polaris/README.MD create mode 100644 contrib/registry/polaris/README_ZH.MD diff --git a/contrib/registry/etcd/etcd_registry.go b/contrib/registry/etcd/etcd_registry.go index 2a4baad0ede..71e711cdb54 100644 --- a/contrib/registry/etcd/etcd_registry.go +++ b/contrib/registry/etcd/etcd_registry.go @@ -43,7 +43,7 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { return err } go r.doKeepAlive(grant.ID, keepAliceCh) - service.Separator = gsvc.Separator() + service.Separator = gsvc.DefaultSeparator return nil } diff --git a/contrib/registry/polaris/README.MD b/contrib/registry/polaris/README.MD new file mode 100644 index 00000000000..9fd2927abb9 --- /dev/null +++ b/contrib/registry/polaris/README.MD @@ -0,0 +1,94 @@ +# GoFrame Polaris Registry + +English | [简体中文](README_ZH.MD) + +Use Polaris mesh as service registration, discovery management and heartbeat reporting + + +## Installation +``` +go get -u -v github.com/gogf/gf/contrib/registry/polaris/v2 +``` +suggested using `go.mod`: +``` +require github.com/gogf/gf/contrib/registry/polaris/v2 latest +``` + +## Limitation +``` +golang version >= 1.15 +``` + + +## Example + +### Reference example + +[server](example/registry/polaris/server/main.go) +```go +package main + +import ( + "github.com/polarismesh/polaris-go/pkg/config" + + "github.com/gogf/gf/contrib/registry/polaris/v2" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/net/gsvc" +) + +func main() { + conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) + + // TTL egt 2*time.Second + gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100))) + + s := g.Server(`hello.svc`) + s.BindHandler("/", func(r *ghttp.Request) { + g.Log().Info(r.Context(), `request received`) + r.Response.Write(`Hello world`) + }) + s.Run() +} + +``` + +[client](example/registry/polaris/client/main.go) +```go +package main + +import ( + "fmt" + "time" + + "github.com/polarismesh/polaris-go/pkg/config" + + "github.com/gogf/gf/contrib/registry/polaris/v2" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/os/gctx" +) + +func main() { + conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) + + gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100))) + + for i := 0; i < 100; i++ { + res, err := g.Client().Get(gctx.New(), `http://hello.svc/`) + if err != nil { + panic(err) + } + fmt.Println(res.ReadAllString()) + res.Close() + time.Sleep(time.Second) + } +} + +``` + +## License + +`GoFrame Polaris` is licensed under the [MIT License](../../../LICENSE), 100% free and open-source, forever. + diff --git a/contrib/registry/polaris/README_ZH.MD b/contrib/registry/polaris/README_ZH.MD new file mode 100644 index 00000000000..47ab34ced22 --- /dev/null +++ b/contrib/registry/polaris/README_ZH.MD @@ -0,0 +1,93 @@ +# GoFrame Polaris Registry + +[English](README.MD) | 简体中文 + +使用Polarismesh作为服务注册、发现管理和心跳上报 + + +## Installation +``` +go get -u -v github.com/gogf/gf/contrib/registry/polaris/v2 +``` +suggested using `go.mod`: +``` +require github.com/gogf/gf/contrib/registry/polaris/v2 latest +``` + +## Limitation +``` +golang version >= 1.15 +``` + + +## 示例 + +### 引用示例 + +[服务端](example/registry/polaris/server/main.go) +```go +package main + +import ( + "github.com/polarismesh/polaris-go/pkg/config" + + "github.com/gogf/gf/contrib/registry/polaris/v2" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/net/gsvc" +) + +func main() { + conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) + + // TTL egt 2*time.Second + gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100))) + + s := g.Server(`hello.svc`) + s.BindHandler("/", func(r *ghttp.Request) { + g.Log().Info(r.Context(), `request received`) + r.Response.Write(`Hello world`) + }) + s.Run() +} + +``` + +[客户端](example/registry/polaris/client/main.go) +```go +package main + +import ( + "fmt" + "time" + + "github.com/polarismesh/polaris-go/pkg/config" + + "github.com/gogf/gf/contrib/registry/polaris/v2" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/os/gctx" +) + +func main() { + conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) + + gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100))) + + for i := 0; i < 100; i++ { + res, err := g.Client().Get(gctx.New(), `http://hello.svc/`) + if err != nil { + panic(err) + } + fmt.Println(res.ReadAllString()) + res.Close() + time.Sleep(time.Second) + } +} + +``` + +## 协议 + +`GoFrame Polaris` 使用非常友好的 [MIT](../../../LICENSE) 开源协议进行发布,永久`100%`开源免费。 \ No newline at end of file diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index f00ba678ca4..2de9af56eff 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -21,11 +21,14 @@ import ( ) var ( - _ gsvc.Registrar = &Registry{} + _ gsvc.Registry = &Registry{} ) -// _instanceIDSeparator Instance id Separator. -const _instanceIDSeparator = "-" +const ( + // instanceIDSeparator Instance id Separator. + instanceIDSeparator = "-" + endpointDelimiter = ":" +) type options struct { // required, namespace in polaris @@ -180,7 +183,7 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { } name := "" - names := strings.Split(instance.GetService(), _instanceIDSeparator) + names := strings.Split(instance.GetService(), instanceIDSeparator) if names != nil && len(names) > 4 { return &gsvc.Service{ Prefix: names[0], @@ -190,7 +193,7 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { Version: metadata["version"], Metadata: gconv.Map(metadata), Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())}, - Separator: _instanceIDSeparator, + Separator: instanceIDSeparator, } } @@ -199,6 +202,6 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { Version: metadata["version"], Metadata: gconv.Map(metadata), Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, instance.GetHost(), instance.GetPort())}, - Separator: _instanceIDSeparator, + Separator: instanceIDSeparator, } } diff --git a/contrib/registry/polaris/polaris_discovery.go b/contrib/registry/polaris/polaris_discovery.go index 524e3d267a6..629ce512cfd 100644 --- a/contrib/registry/polaris/polaris_discovery.go +++ b/contrib/registry/polaris/polaris_discovery.go @@ -17,7 +17,7 @@ import ( // Search returns the service instances in memory according to the service name. func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { - in.Separator = _instanceIDSeparator + in.Separator = instanceIDSeparator // get all instances instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ GetAllInstancesRequest: model.GetAllInstancesRequest{ diff --git a/contrib/registry/polaris/polaris_registry.go b/contrib/registry/polaris/polaris_registry.go index fe9fbe97a97..4b33b68157b 100644 --- a/contrib/registry/polaris/polaris_registry.go +++ b/contrib/registry/polaris/polaris_registry.go @@ -8,6 +8,7 @@ package polaris import ( "context" + "errors" "net" "net/url" "strconv" @@ -26,22 +27,16 @@ import ( func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) error { ids := make([]string, 0, len(serviceInstance.Endpoints)) // set separator - serviceInstance.Separator = _instanceIDSeparator + serviceInstance.Separator = instanceIDSeparator for _, endpoint := range serviceInstance.Endpoints { - // get url - u, err := url.Parse(endpoint) - if err != nil { - return err - } - - // get host and port - host, port, err := net.SplitHostPort(u.Host) - if err != nil { - return err + httpArr := strings.Split(endpoint, endpointDelimiter) + if len(httpArr) < 2 { + return errors.New("invalid endpoint") } + host := httpArr[0] // port to int - portNum, err := strconv.Atoi(port) + portNum, err := strconv.Atoi(httpArr[1]) if err != nil { return err } @@ -50,16 +45,20 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) var rmd map[string]interface{} if serviceInstance.Metadata == nil { rmd = map[string]interface{}{ - "kind": u.Scheme, + "kind": gsvc.DefaultProtocol, "version": serviceInstance.Version, } } else { rmd = make(map[string]interface{}, len(serviceInstance.Metadata)+2) + if protocol, ok := serviceInstance.Metadata[gsvc.MDProtocol].(string); !ok { + rmd["kind"] = gsvc.DefaultProtocol + } else { + rmd["kind"] = protocol + } + rmd["version"] = serviceInstance.Version for k, v := range serviceInstance.Metadata { rmd[k] = v } - rmd["kind"] = u.Scheme - rmd["version"] = serviceInstance.Version } // Register service, err := r.provider.Register( @@ -119,15 +118,15 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) ids = append(ids, instanceID) } // need to set InstanceID for Deregister - serviceInstance.ID = strings.Join(ids, _instanceIDSeparator) + serviceInstance.ID = strings.Join(ids, instanceIDSeparator) return nil } // Deregister the registration. func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service) error { - split := strings.Split(serviceInstance.ID, _instanceIDSeparator) - serviceInstance.Separator = _instanceIDSeparator + split := strings.Split(serviceInstance.ID, instanceIDSeparator) + serviceInstance.Separator = instanceIDSeparator for i, endpoint := range serviceInstance.Endpoints { // get url u, err := url.Parse(endpoint) diff --git a/contrib/registry/polaris/polaris_test.go b/contrib/registry/polaris/polaris_test.go index 98d62510949..44d102d5b8e 100644 --- a/contrib/registry/polaris/polaris_test.go +++ b/contrib/registry/polaris/polaris_test.go @@ -35,7 +35,7 @@ func TestRegistry(t *testing.T) { Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, - Separator: _instanceIDSeparator, + Separator: instanceIDSeparator, } err := r.Register(ctx, svc) @@ -64,21 +64,21 @@ func TestRegistryMany(t *testing.T) { Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, - Separator: _instanceIDSeparator, + Separator: instanceIDSeparator, } svc1 := &gsvc.Service{ Name: "goframe-provider-2-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9001?isSecure=false"}, - Separator: _instanceIDSeparator, + Separator: instanceIDSeparator, } svc2 := &gsvc.Service{ Name: "goframe-provider-3-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9002?isSecure=false"}, - Separator: _instanceIDSeparator, + Separator: instanceIDSeparator, } err := r.Register(context.Background(), svc) @@ -129,7 +129,7 @@ func TestGetService(t *testing.T) { Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, - Separator: _instanceIDSeparator, + Separator: instanceIDSeparator, } err := r.Register(ctx, svc) @@ -175,7 +175,7 @@ func TestWatch(t *testing.T) { Version: "test", Metadata: map[string]interface{}{"app": "goframe"}, Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, - Separator: _instanceIDSeparator, + Separator: instanceIDSeparator, } watch, err := r.Watch(context.Background(), svc.KeyWithoutEndpoints()) diff --git a/net/ghttp/ghttp_server_registry.go b/net/ghttp/ghttp_server_registry.go index 8a6d5989a05..2659740dc8c 100644 --- a/net/ghttp/ghttp_server_registry.go +++ b/net/ghttp/ghttp_server_registry.go @@ -22,7 +22,7 @@ func (s *Server) doServiceRegister() { } var ( ctx = context.Background() - protocol = `http` + protocol = gsvc.DefaultProtocol insecure = true address = s.config.Address ) @@ -47,7 +47,7 @@ func (s *Server) doServiceRegister() { } s.service = &gsvc.Service{ Name: s.GetName(), - Endpoints: []string{fmt.Sprintf(`%s://%s:%s`, protocol, ip, port)}, + Endpoints: []string{fmt.Sprintf(`%s:%s`, ip, port)}, Metadata: metadata, } s.Logger().Debugf(ctx, `service register: %+v`, s.service) diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index 163b8c594d6..314b367a3ef 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -102,6 +102,7 @@ const ( MDInsecure = `insecure` MDWeight = `weight` defaultTimeout = 5 * time.Second + DefaultProtocol = `http` ) var defaultRegistry Registry diff --git a/net/gsvc/gsvc_search.go b/net/gsvc/gsvc_search.go index 83b76dd7e9f..8845bffa869 100644 --- a/net/gsvc/gsvc_search.go +++ b/net/gsvc/gsvc_search.go @@ -8,25 +8,26 @@ package gsvc // Key formats and returns a string for prefix searching purpose. func (s *SearchInput) Key() string { - if s.Separator == "" { - s.Separator = defaultSeparator + separator := DefaultSeparator + if s.Separator != "" { + separator = s.Separator } keyPrefix := "" if s.Prefix != "" { - if s.Separator == defaultSeparator { - keyPrefix += s.Separator + s.Prefix + if s.Separator == DefaultSeparator { + keyPrefix += separator + s.Prefix } else { keyPrefix += s.Prefix } } if s.Deployment != "" { - keyPrefix += s.Separator + s.Deployment + keyPrefix += separator + s.Deployment if s.Namespace != "" { - keyPrefix += s.Separator + s.Namespace + keyPrefix += separator + s.Namespace if s.Name != "" { - keyPrefix += s.Separator + s.Name + keyPrefix += separator + s.Name if s.Version != "" { - keyPrefix += s.Separator + s.Version + keyPrefix += separator + s.Version } } } diff --git a/net/gsvc/gsvc_service.go b/net/gsvc/gsvc_service.go index aabea49076f..4ca87c58922 100644 --- a/net/gsvc/gsvc_service.go +++ b/net/gsvc/gsvc_service.go @@ -19,15 +19,11 @@ import ( ) const ( - defaultSeparator = "/" - delimiter = "," + // DefaultSeparator is the default separator for the service name and method name. + DefaultSeparator = "/" + endpointDelimiter = "," ) -// Separator is the default defaultSeparator for path. -func Separator() string { - return defaultSeparator -} - // NewServiceWithName creates and returns service from `name`. func NewServiceWithName(name string) (s *Service) { s = &Service{ @@ -40,7 +36,7 @@ func NewServiceWithName(name string) (s *Service) { // NewServiceWithKV creates and returns service from `key` and `value`. func NewServiceWithKV(key, value []byte) (s *Service, err error) { - array := gstr.Split(gstr.Trim(string(key), defaultSeparator), defaultSeparator) + array := gstr.Split(gstr.Trim(string(key), DefaultSeparator), DefaultSeparator) if len(array) < 6 { err = gerror.NewCodef(gcode.CodeInvalidParameter, `invalid service key "%s"`, key) @@ -52,9 +48,9 @@ func NewServiceWithKV(key, value []byte) (s *Service, err error) { Namespace: array[2], Name: array[3], Version: array[4], - Endpoints: gstr.Split(array[5], delimiter), + Endpoints: gstr.Split(array[5], endpointDelimiter), Metadata: make(Metadata), - Separator: defaultSeparator, + Separator: DefaultSeparator, } s.autoFillDefaultAttributes() if len(value) > 0 { @@ -68,11 +64,12 @@ func NewServiceWithKV(key, value []byte) (s *Service, err error) { // Key formats the service information and returns the Service as registering key. func (s *Service) Key() string { - if s.Separator == "" { - s.Separator = defaultSeparator + defaultSeparator := DefaultSeparator + if s.Separator != "" { + defaultSeparator = s.Separator } serviceNameUnique := s.KeyWithoutEndpoints() - serviceNameUnique += s.Separator + gstr.Join(s.Endpoints, ",") + serviceNameUnique += defaultSeparator + gstr.Join(s.Endpoints, ",") return serviceNameUnique } @@ -84,13 +81,14 @@ func (s *Service) KeyWithSchema() string { // KeyWithoutEndpoints formats the service information and returns a string as a unique name of service. func (s *Service) KeyWithoutEndpoints() string { s.autoFillDefaultAttributes() - if s.Separator == "" { - s.Separator = defaultSeparator + defaultSeparator := DefaultSeparator + if s.Separator != "" { + defaultSeparator = s.Separator } - if s.Separator != defaultSeparator { - return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) + if s.Separator != DefaultSeparator { + return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, defaultSeparator) } - return s.Separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) + return defaultSeparator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, defaultSeparator) } // Value formats the service information and returns the Service as registering value. diff --git a/text/gstr/gstr_convert.go b/text/gstr/gstr_convert.go index badfda24120..45866509ed7 100644 --- a/text/gstr/gstr_convert.go +++ b/text/gstr/gstr_convert.go @@ -18,6 +18,11 @@ import ( "github.com/gogf/gf/v2/util/grand" ) +var ( + // octReg is the regular expression object for checks octal string. + octReg = regexp.MustCompile(`\\[0-7]{3}`) +) + // Chr return the ascii string of a number(0-255). func Chr(ascii int) string { return string([]byte{byte(ascii % 256)}) @@ -28,11 +33,6 @@ func Ord(char string) int { return int(char[0]) } -var ( - // octReg is the regular expression object for checks octal string. - octReg = regexp.MustCompile(`\\[0-7]{3}`) -) - // OctStr converts string container octal string to its original string, // for example, to Chinese string. // Eg: `\346\200\241` -> 怡 From 53e054320fde6a49322b8459394e26840ce327d8 Mon Sep 17 00:00:00 2001 From: houseme Date: Fri, 13 May 2022 20:04:25 +0800 Subject: [PATCH 64/70] fix --- contrib/registry/polaris/polaris.go | 22 +++++++++++ contrib/registry/polaris/polaris_registry.go | 41 ++++---------------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index 2de9af56eff..e81d03803b9 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -8,7 +8,10 @@ package polaris import ( + "context" + "errors" "fmt" + "strconv" "strings" "time" @@ -17,6 +20,7 @@ import ( "github.com/polarismesh/polaris-go/pkg/model" "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" ) @@ -205,3 +209,21 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { Separator: instanceIDSeparator, } } + +// getHostAndPortFromEndpoint get host and port from endpoint. +func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) { + endpoint = gstr.ReplaceByArray(endpoint, []string{"tcp://", "udp://", "http://", "https://"}) + httpArr := gstr.Split(endpoint, endpointDelimiter) + if len(httpArr) < 2 { + err = errors.New("invalid endpoint") + return + } + host = httpArr[0] + + // port to int + port, err = strconv.Atoi(httpArr[1]) + if err != nil { + return + } + return +} diff --git a/contrib/registry/polaris/polaris_registry.go b/contrib/registry/polaris/polaris_registry.go index 4b33b68157b..bb0282692fd 100644 --- a/contrib/registry/polaris/polaris_registry.go +++ b/contrib/registry/polaris/polaris_registry.go @@ -8,11 +8,6 @@ package polaris import ( "context" - "errors" - "net" - "net/url" - "strconv" - "strings" "time" "github.com/polarismesh/polaris-go/api" @@ -20,6 +15,7 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" ) @@ -29,14 +25,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) // set separator serviceInstance.Separator = instanceIDSeparator for _, endpoint := range serviceInstance.Endpoints { - httpArr := strings.Split(endpoint, endpointDelimiter) - if len(httpArr) < 2 { - return errors.New("invalid endpoint") - } - host := httpArr[0] - - // port to int - portNum, err := strconv.Atoi(httpArr[1]) + host, portNum, err := getHostAndPortFromEndpoint(ctx, endpoint) if err != nil { return err } @@ -50,10 +39,9 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) } } else { rmd = make(map[string]interface{}, len(serviceInstance.Metadata)+2) - if protocol, ok := serviceInstance.Metadata[gsvc.MDProtocol].(string); !ok { - rmd["kind"] = gsvc.DefaultProtocol - } else { - rmd["kind"] = protocol + rmd["kind"] = gsvc.DefaultProtocol + if protocol, ok := serviceInstance.Metadata[gsvc.MDProtocol]; ok { + rmd["kind"] = gconv.String(protocol) } rmd["version"] = serviceInstance.Version for k, v := range serviceInstance.Metadata { @@ -118,30 +106,17 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) ids = append(ids, instanceID) } // need to set InstanceID for Deregister - serviceInstance.ID = strings.Join(ids, instanceIDSeparator) + serviceInstance.ID = gstr.Join(ids, instanceIDSeparator) return nil } // Deregister the registration. func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service) error { - split := strings.Split(serviceInstance.ID, instanceIDSeparator) + split := gstr.Split(serviceInstance.ID, instanceIDSeparator) serviceInstance.Separator = instanceIDSeparator for i, endpoint := range serviceInstance.Endpoints { - // get url - u, err := url.Parse(endpoint) - if err != nil { - return err - } - - // get host and port - host, port, err := net.SplitHostPort(u.Host) - if err != nil { - return err - } - - // port to int - portNum, err := strconv.Atoi(port) + host, portNum, err := getHostAndPortFromEndpoint(ctx, endpoint) if err != nil { return err } From 79595319ab39eea46e009694bb9f55def5f592d6 Mon Sep 17 00:00:00 2001 From: houseme Date: Fri, 13 May 2022 21:47:01 +0800 Subject: [PATCH 65/70] fix --- contrib/registry/polaris/go.sum | 63 ++++++++++++++++------------- contrib/registry/polaris/polaris.go | 17 +++++--- example/go.sum | 11 ++++- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum index bffe7ed1ce1..9d519cc0bd5 100644 --- a/contrib/registry/polaris/go.sum +++ b/contrib/registry/polaris/go.sum @@ -65,6 +65,7 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP 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-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -93,10 +94,13 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb 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-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= +github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= -github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -146,8 +150,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 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 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -196,11 +200,15 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/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/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= +github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -271,6 +279,8 @@ github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= 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= @@ -286,25 +296,26 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf 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/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= -go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= -go.opentelemetry.io/otel/sdk v1.0.0 h1:BNPMYUONPNbLneMttKSjQhOTlFLOD9U22HNG1KrIN2Y= -go.opentelemetry.io/otel/sdk v1.0.0/go.mod h1:PCrDHlSy5x1kjezSdL37PhbFUMjrsLRshJ2zCzeXwbM= -go.opentelemetry.io/otel/trace v1.0.0 h1:TSBr8GTEtKevYMG/2d21M989r5WJYVimhTHBKVEZuh4= -go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs= +go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= +go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= +go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0= +go.opentelemetry.io/otel/sdk v1.7.0/go.mod h1:uTEOTwaqIVuTGiJN7ii13Ibp75wJmYUDe374q6cZwUU= +go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o= +go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= @@ -320,7 +331,6 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U 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-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -352,9 +362,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= -golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= 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= @@ -386,14 +395,13 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -456,25 +464,22 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8-0.20220428233042-78819d01d041 h1:dejsXyH3RsgJiGtZB8yNSjsPzZU/hAJ8aMJmRi7+Dtk= -golang.org/x/text v0.3.8-0.20220428233042-78819d01d041/go.mod h1:UqJy94PED2GK2o3pz2dHDKz1s05DEJMG9tubaZ3t0uI= +golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= +golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -521,8 +526,8 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= -golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= +golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= 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= diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index e81d03803b9..a5f8a20da68 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -9,7 +9,6 @@ package polaris import ( "context" - "errors" "fmt" "strconv" "strings" @@ -19,6 +18,7 @@ import ( "github.com/polarismesh/polaris-go/pkg/config" "github.com/polarismesh/polaris-go/pkg/model" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/net/gsvc" "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" @@ -212,16 +212,23 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { // getHostAndPortFromEndpoint get host and port from endpoint. func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) { - endpoint = gstr.ReplaceByArray(endpoint, []string{"tcp://", "udp://", "http://", "https://"}) + endpoint = gstr.ReplaceByArray(endpoint, []string{"tcp://", "", "udp://", "", "http://", "", "https://", "", "ws://", "", "wss://", ""}) httpArr := gstr.Split(endpoint, endpointDelimiter) if len(httpArr) < 2 { - err = errors.New("invalid endpoint") + err = gerror.New("invalid endpoint") return } host = httpArr[0] - // port to int - port, err = strconv.Atoi(httpArr[1]) + portArr := gstr.Split(httpArr[1], "?") + if len(portArr) > 1 { + // port to int + port, err = strconv.Atoi(portArr[0]) + } else { + // port to int + port, err = strconv.Atoi(httpArr[1]) + } + if err != nil { return } diff --git a/example/go.sum b/example/go.sum index e53038b0b1b..16505724d8d 100644 --- a/example/go.sum +++ b/example/go.sum @@ -75,6 +75,7 @@ github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmf github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -226,11 +227,15 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/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/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= +github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= @@ -305,6 +310,8 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= 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= From 8450dea255426a83b8a80226fa5b32054fc93517 Mon Sep 17 00:00:00 2001 From: houseme Date: Sun, 15 May 2022 12:15:49 +0800 Subject: [PATCH 66/70] feat:modify package --- contrib/registry/polaris/polaris.go | 12 ++++++------ contrib/registry/polaris/polaris_discovery.go | 6 ++---- contrib/registry/polaris/polaris_registry.go | 8 ++++---- contrib/registry/polaris/polaris_watcher.go | 6 +++--- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index a5f8a20da68..36641a84f12 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -14,7 +14,7 @@ import ( "strings" "time" - "github.com/polarismesh/polaris-go/api" + "github.com/polarismesh/polaris-go" "github.com/polarismesh/polaris-go/pkg/config" "github.com/polarismesh/polaris-go/pkg/model" @@ -76,8 +76,8 @@ type Option func(o *options) // Registry is polaris registry. type Registry struct { opt options - provider api.ProviderAPI - consumer api.ConsumerAPI + provider polaris.ProviderAPI + consumer polaris.ConsumerAPI } // WithNamespace with the Namespace option. @@ -131,7 +131,7 @@ func WithHeartbeat(heartbeat bool) Option { } // NewRegistry create a new registry. -func NewRegistry(provider api.ProviderAPI, consumer api.ConsumerAPI, opts ...Option) (r *Registry) { +func NewRegistry(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Option) (r *Registry) { op := options{ Namespace: "default", ServiceToken: "", @@ -157,11 +157,11 @@ func NewRegistry(provider api.ProviderAPI, consumer api.ConsumerAPI, opts ...Opt // NewRegistryWithConfig new a registry with config. func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Registry) { - provider, err := api.NewProviderAPIByConfig(conf) + provider, err := polaris.NewProviderAPIByConfig(conf) if err != nil { panic(err) } - consumer, err := api.NewConsumerAPIByConfig(conf) + consumer, err := polaris.NewConsumerAPIByConfig(conf) if err != nil { panic(err) } diff --git a/contrib/registry/polaris/polaris_discovery.go b/contrib/registry/polaris/polaris_discovery.go index 629ce512cfd..51c74ab9e15 100644 --- a/contrib/registry/polaris/polaris_discovery.go +++ b/contrib/registry/polaris/polaris_discovery.go @@ -9,7 +9,7 @@ package polaris import ( "context" - "github.com/polarismesh/polaris-go/api" + "github.com/polarismesh/polaris-go" "github.com/polarismesh/polaris-go/pkg/model" "github.com/gogf/gf/v2/net/gsvc" @@ -19,7 +19,7 @@ import ( func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { in.Separator = instanceIDSeparator // get all instances - instancesResponse, err := r.consumer.GetAllInstances(&api.GetAllInstancesRequest{ + instancesResponse, err := r.consumer.GetAllInstances(&polaris.GetAllInstancesRequest{ GetAllInstancesRequest: model.GetAllInstancesRequest{ Service: in.Key(), Namespace: r.opt.Namespace, @@ -30,9 +30,7 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Ser if err != nil { return nil, err } - serviceInstances := instancesToServiceInstances(instancesResponse.GetInstances()) - return serviceInstances, nil } diff --git a/contrib/registry/polaris/polaris_registry.go b/contrib/registry/polaris/polaris_registry.go index bb0282692fd..48fe0f5d327 100644 --- a/contrib/registry/polaris/polaris_registry.go +++ b/contrib/registry/polaris/polaris_registry.go @@ -10,7 +10,7 @@ import ( "context" "time" - "github.com/polarismesh/polaris-go/api" + "github.com/polarismesh/polaris-go" "github.com/polarismesh/polaris-go/pkg/model" "github.com/gogf/gf/v2/frame/g" @@ -50,7 +50,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) } // Register service, err := r.provider.Register( - &api.InstanceRegisterRequest{ + &polaris.InstanceRegisterRequest{ InstanceRegisterRequest: model.InstanceRegisterRequest{ Service: serviceInstance.KeyWithoutEndpoints(), ServiceToken: r.opt.ServiceToken, @@ -83,7 +83,7 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) for { <-ticker.C - err = r.provider.Heartbeat(&api.InstanceHeartbeatRequest{ + err = r.provider.Heartbeat(&polaris.InstanceHeartbeatRequest{ InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{ Service: serviceInstance.KeyWithoutEndpoints(), Namespace: r.opt.Namespace, @@ -122,7 +122,7 @@ func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service } // Deregister err = r.provider.Deregister( - &api.InstanceDeRegisterRequest{ + &polaris.InstanceDeRegisterRequest{ InstanceDeRegisterRequest: model.InstanceDeRegisterRequest{ Service: serviceInstance.KeyWithoutEndpoints(), ServiceToken: r.opt.ServiceToken, diff --git a/contrib/registry/polaris/polaris_watcher.go b/contrib/registry/polaris/polaris_watcher.go index 053f657bfa5..00d040c8dc6 100644 --- a/contrib/registry/polaris/polaris_watcher.go +++ b/contrib/registry/polaris/polaris_watcher.go @@ -9,7 +9,7 @@ package polaris import ( "context" - "github.com/polarismesh/polaris-go/api" + "github.com/polarismesh/polaris-go" "github.com/polarismesh/polaris-go/pkg/model" "github.com/gogf/gf/v2/net/gsvc" @@ -25,8 +25,8 @@ type Watcher struct { ServiceInstances []*gsvc.Service } -func newWatcher(ctx context.Context, namespace string, serviceName string, consumer api.ConsumerAPI) (*Watcher, error) { - watchServiceResponse, err := consumer.WatchService(&api.WatchServiceRequest{ +func newWatcher(ctx context.Context, namespace string, serviceName string, consumer polaris.ConsumerAPI) (*Watcher, error) { + watchServiceResponse, err := consumer.WatchService(&polaris.WatchServiceRequest{ WatchServiceRequest: model.WatchServiceRequest{ Key: model.ServiceKey{ Namespace: namespace, From 4eeb876ddd461398b67921136008e623f5deda3e Mon Sep 17 00:00:00 2001 From: houseme Date: Mon, 16 May 2022 20:53:04 +0800 Subject: [PATCH 67/70] improve code --- .../{etcd_registry.go => etcd_registrar.go} | 2 + contrib/registry/polaris/polaris.go | 42 ++++++------------- ...laris_registry.go => polaris_registrar.go} | 0 contrib/registry/polaris/polaris_test.go | 32 +++++++------- example/registry/polaris/client/main.go | 2 +- example/registry/polaris/server/main.go | 2 +- net/gsvc/gsvc_search.go | 2 +- net/gsvc/gsvc_service.go | 16 +++---- 8 files changed, 42 insertions(+), 56 deletions(-) rename contrib/registry/etcd/{etcd_registry.go => etcd_registrar.go} (94%) rename contrib/registry/polaris/{polaris_registry.go => polaris_registrar.go} (100%) diff --git a/contrib/registry/etcd/etcd_registry.go b/contrib/registry/etcd/etcd_registrar.go similarity index 94% rename from contrib/registry/etcd/etcd_registry.go rename to contrib/registry/etcd/etcd_registrar.go index 71e711cdb54..99f52b5c5b2 100644 --- a/contrib/registry/etcd/etcd_registry.go +++ b/contrib/registry/etcd/etcd_registrar.go @@ -15,6 +15,7 @@ import ( "github.com/gogf/gf/v2/net/gsvc" ) +// Register implements the gsvc.Register interface. func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { r.lease = etcd3.NewLease(r.client) grant, err := r.lease.Grant(ctx, int64(r.keepaliveTTL.Seconds())) @@ -47,6 +48,7 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { return nil } +// Deregister implements the gsvc.Deregister interface. func (r *Registry) Deregister(ctx context.Context, service *gsvc.Service) error { _, err := r.client.Delete(ctx, service.Key()) if r.lease != nil { diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index 36641a84f12..aa3e57a7670 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -130,8 +130,8 @@ func WithHeartbeat(heartbeat bool) Option { return func(o *options) { o.Heartbeat = heartbeat } } -// NewRegistry create a new registry. -func NewRegistry(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Option) (r *Registry) { +// New create a new registry. +func New(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Option) (r *Registry) { op := options{ Namespace: "default", ServiceToken: "", @@ -155,8 +155,8 @@ func NewRegistry(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opt } } -// NewRegistryWithConfig new a registry with config. -func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Registry) { +// NewWithConfig new a registry with config. +func NewWithConfig(conf config.Configuration, opts ...Option) (r *Registry) { provider, err := polaris.NewProviderAPIByConfig(conf) if err != nil { panic(err) @@ -165,7 +165,7 @@ func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Regist if err != nil { panic(err) } - return NewRegistry(provider, consumer, opts...) + return New(provider, consumer, opts...) } func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service { @@ -180,13 +180,6 @@ func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service { func instanceToServiceInstance(instance model.Instance) *gsvc.Service { metadata := instance.GetMetadata() - // Usually, it won't fail in goframe if register correctly - kind := "" - if k, ok := metadata["kind"]; ok { - kind = k - } - - name := "" names := strings.Split(instance.GetService(), instanceIDSeparator) if names != nil && len(names) > 4 { return &gsvc.Service{ @@ -202,34 +195,25 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { } return &gsvc.Service{ - Name: name, + Name: instance.GetService(), + Namespace: instance.GetNamespace(), Version: metadata["version"], Metadata: gconv.Map(metadata), - Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, instance.GetHost(), instance.GetPort())}, + Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())}, Separator: instanceIDSeparator, } } // getHostAndPortFromEndpoint get host and port from endpoint. func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) { - endpoint = gstr.ReplaceByArray(endpoint, []string{"tcp://", "", "udp://", "", "http://", "", "https://", "", "ws://", "", "wss://", ""}) - httpArr := gstr.Split(endpoint, endpointDelimiter) - if len(httpArr) < 2 { + endpoints := gstr.SplitAndTrim(endpoint, endpointDelimiter) + if len(endpoints) < 2 { err = gerror.New("invalid endpoint") return } - host = httpArr[0] - - portArr := gstr.Split(httpArr[1], "?") - if len(portArr) > 1 { - // port to int - port, err = strconv.Atoi(portArr[0]) - } else { - // port to int - port, err = strconv.Atoi(httpArr[1]) - } - - if err != nil { + host = endpoints[0] + // port to int + if port, err = strconv.Atoi(endpoints[1]); err != nil { return } return diff --git a/contrib/registry/polaris/polaris_registry.go b/contrib/registry/polaris/polaris_registrar.go similarity index 100% rename from contrib/registry/polaris/polaris_registry.go rename to contrib/registry/polaris/polaris_registrar.go diff --git a/contrib/registry/polaris/polaris_test.go b/contrib/registry/polaris/polaris_test.go index 44d102d5b8e..10e119a1e25 100644 --- a/contrib/registry/polaris/polaris_test.go +++ b/contrib/registry/polaris/polaris_test.go @@ -22,7 +22,7 @@ import ( func TestRegistry(t *testing.T) { conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) - r := NewRegistryWithConfig( + r := NewWithConfig( conf, WithTimeout(time.Second*10), WithTTL(100), @@ -33,8 +33,8 @@ func TestRegistry(t *testing.T) { svc := &gsvc.Service{ Name: "goframe-provider-0-tcp", Version: "test", - Metadata: map[string]interface{}{"app": "goframe"}, - Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, + Endpoints: []string{"127.0.0.1:9000"}, Separator: instanceIDSeparator, } @@ -53,7 +53,7 @@ func TestRegistry(t *testing.T) { func TestRegistryMany(t *testing.T) { conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) - r := NewRegistryWithConfig( + r := NewWithConfig( conf, WithTimeout(time.Second*10), WithTTL(100), @@ -62,22 +62,22 @@ func TestRegistryMany(t *testing.T) { svc := &gsvc.Service{ Name: "goframe-provider-1-tcp", Version: "test", - Metadata: map[string]interface{}{"app": "goframe"}, - Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, + Endpoints: []string{"127.0.0.1:9000"}, Separator: instanceIDSeparator, } svc1 := &gsvc.Service{ Name: "goframe-provider-2-tcp", Version: "test", - Metadata: map[string]interface{}{"app": "goframe"}, - Endpoints: []string{"tcp://127.0.0.1:9001?isSecure=false"}, + Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, + Endpoints: []string{"127.0.0.1:9001"}, Separator: instanceIDSeparator, } svc2 := &gsvc.Service{ Name: "goframe-provider-3-tcp", Version: "test", - Metadata: map[string]interface{}{"app": "goframe"}, - Endpoints: []string{"tcp://127.0.0.1:9002?isSecure=false"}, + Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, + Endpoints: []string{"127.0.0.1:9002"}, Separator: instanceIDSeparator, } @@ -116,7 +116,7 @@ func TestRegistryMany(t *testing.T) { func TestGetService(t *testing.T) { conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) - r := NewRegistryWithConfig( + r := NewWithConfig( conf, WithTimeout(time.Second*10), WithTTL(100), @@ -127,8 +127,8 @@ func TestGetService(t *testing.T) { svc := &gsvc.Service{ Name: "goframe-provider-4-tcp", Version: "test", - Metadata: map[string]interface{}{"app": "goframe"}, - Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, + Endpoints: []string{"127.0.0.1:9000"}, Separator: instanceIDSeparator, } @@ -162,7 +162,7 @@ func TestGetService(t *testing.T) { func TestWatch(t *testing.T) { conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) - r := NewRegistryWithConfig( + r := NewWithConfig( conf, WithTimeout(time.Second*10), WithTTL(100), @@ -173,8 +173,8 @@ func TestWatch(t *testing.T) { svc := &gsvc.Service{ Name: "goframe-provider-4-tcp", Version: "test", - Metadata: map[string]interface{}{"app": "goframe"}, - Endpoints: []string{"tcp://127.0.0.1:9000?isSecure=false"}, + Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, + Endpoints: []string{"127.0.0.1:9000"}, Separator: instanceIDSeparator, } diff --git a/example/registry/polaris/client/main.go b/example/registry/polaris/client/main.go index 5c45087a2b4..466eb937474 100644 --- a/example/registry/polaris/client/main.go +++ b/example/registry/polaris/client/main.go @@ -16,7 +16,7 @@ import ( func main() { conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) - gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100))) + gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(100))) for i := 0; i < 100; i++ { res, err := g.Client().Get(gctx.New(), `http://hello.svc/`) diff --git a/example/registry/polaris/server/main.go b/example/registry/polaris/server/main.go index a7ab6f33867..63608d085a9 100644 --- a/example/registry/polaris/server/main.go +++ b/example/registry/polaris/server/main.go @@ -13,7 +13,7 @@ func main() { conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) // TTL egt 2*time.Second - gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100))) + gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(100))) s := g.Server(`hello.svc`) s.BindHandler("/", func(r *ghttp.Request) { diff --git a/net/gsvc/gsvc_search.go b/net/gsvc/gsvc_search.go index 8845bffa869..1e76e9e63ce 100644 --- a/net/gsvc/gsvc_search.go +++ b/net/gsvc/gsvc_search.go @@ -14,7 +14,7 @@ func (s *SearchInput) Key() string { } keyPrefix := "" if s.Prefix != "" { - if s.Separator == DefaultSeparator { + if separator == DefaultSeparator { keyPrefix += separator + s.Prefix } else { keyPrefix += s.Prefix diff --git a/net/gsvc/gsvc_service.go b/net/gsvc/gsvc_service.go index 4ca87c58922..7dc971dff1a 100644 --- a/net/gsvc/gsvc_service.go +++ b/net/gsvc/gsvc_service.go @@ -64,12 +64,12 @@ func NewServiceWithKV(key, value []byte) (s *Service, err error) { // Key formats the service information and returns the Service as registering key. func (s *Service) Key() string { - defaultSeparator := DefaultSeparator + separator := DefaultSeparator if s.Separator != "" { - defaultSeparator = s.Separator + separator = s.Separator } serviceNameUnique := s.KeyWithoutEndpoints() - serviceNameUnique += defaultSeparator + gstr.Join(s.Endpoints, ",") + serviceNameUnique += separator + gstr.Join(s.Endpoints, ",") return serviceNameUnique } @@ -81,14 +81,14 @@ func (s *Service) KeyWithSchema() string { // KeyWithoutEndpoints formats the service information and returns a string as a unique name of service. func (s *Service) KeyWithoutEndpoints() string { s.autoFillDefaultAttributes() - defaultSeparator := DefaultSeparator + separator := DefaultSeparator if s.Separator != "" { - defaultSeparator = s.Separator + separator = s.Separator } - if s.Separator != DefaultSeparator { - return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, defaultSeparator) + if separator != DefaultSeparator { + return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator) } - return defaultSeparator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, defaultSeparator) + return separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator) } // Value formats the service information and returns the Service as registering value. From 0863498d94892e0e725b9dea06a5d8a6ae948337 Mon Sep 17 00:00:00 2001 From: houseme Date: Mon, 16 May 2022 21:48:42 +0800 Subject: [PATCH 68/70] fix --- contrib/registry/polaris/polaris.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index aa3e57a7670..f6eb081b342 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -208,12 +208,13 @@ func instanceToServiceInstance(instance model.Instance) *gsvc.Service { func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) { endpoints := gstr.SplitAndTrim(endpoint, endpointDelimiter) if len(endpoints) < 2 { - err = gerror.New("invalid endpoint") + err = gerror.Newf(`invalid endpoint "%s"`, endpoint) return } host = endpoints[0] // port to int if port, err = strconv.Atoi(endpoints[1]); err != nil { + err = gerror.Wrapf(err, `convert port string "%s" to int failed`, endpoints[1]) return } return From fc77c0d8c8593c626204bd406d31857b3c018abf Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 18 May 2022 21:20:24 +0800 Subject: [PATCH 69/70] improve stop heartbeat --- contrib/registry/polaris/polaris.go | 2 + contrib/registry/polaris/polaris_registrar.go | 41 ++++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index f6eb081b342..191ed7f8726 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -78,6 +78,7 @@ type Registry struct { opt options provider polaris.ProviderAPI consumer polaris.ConsumerAPI + c chan struct{} } // WithNamespace with the Namespace option. @@ -152,6 +153,7 @@ func New(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Opt opt: op, provider: provider, consumer: consumer, + c: make(chan struct{}, 1), } } diff --git a/contrib/registry/polaris/polaris_registrar.go b/contrib/registry/polaris/polaris_registrar.go index 48fe0f5d327..8f0424f2c84 100644 --- a/contrib/registry/polaris/polaris_registrar.go +++ b/contrib/registry/polaris/polaris_registrar.go @@ -81,38 +81,41 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) defer ticker.Stop() for { - <-ticker.C - - err = r.provider.Heartbeat(&polaris.InstanceHeartbeatRequest{ - InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{ - Service: serviceInstance.KeyWithoutEndpoints(), - Namespace: r.opt.Namespace, - Host: host, - Port: portNum, - ServiceToken: r.opt.ServiceToken, - InstanceID: instanceID, - Timeout: &r.opt.Timeout, - RetryCount: &r.opt.RetryCount, - }, - }) - if err != nil { - g.Log().Error(ctx, err.Error()) - continue + select { + case <-ticker.C: + err = r.provider.Heartbeat(&polaris.InstanceHeartbeatRequest{ + InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{ + Service: serviceInstance.KeyWithoutEndpoints(), + Namespace: r.opt.Namespace, + Host: host, + Port: portNum, + ServiceToken: r.opt.ServiceToken, + InstanceID: instanceID, + Timeout: &r.opt.Timeout, + RetryCount: &r.opt.RetryCount, + }, + }) + if err != nil { + g.Log().Error(ctx, err.Error()) + continue + } + case <-r.c: + g.Log().Debug(ctx, "stop heartbeat") + return } } }() } - ids = append(ids, instanceID) } // need to set InstanceID for Deregister serviceInstance.ID = gstr.Join(ids, instanceIDSeparator) - return nil } // Deregister the registration. func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service) error { + r.c <- struct{}{} split := gstr.Split(serviceInstance.ID, instanceIDSeparator) serviceInstance.Separator = instanceIDSeparator for i, endpoint := range serviceInstance.Endpoints { From dc6dc31a21a7bb19fdeec2e269f8b4a2f65f9daf Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 18 May 2022 21:49:07 +0800 Subject: [PATCH 70/70] fix:Set to no cached channel --- contrib/registry/polaris/polaris.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index 191ed7f8726..59a251311f6 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -153,7 +153,7 @@ func New(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Opt opt: op, provider: provider, consumer: consumer, - c: make(chan struct{}, 1), + c: make(chan struct{}), } }