This is an automated email from the ASF dual-hosted git repository.

baerwang pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git


The following commit(s) were added to refs/heads/develop by this push:
     new a8d9c6a3 fix: fix doubao comment (#766)
a8d9c6a3 is described below

commit a8d9c6a3a461c29baaf2692d0086c9f7edca6def
Author: Xuetao Li <[email protected]>
AuthorDate: Wed Oct 8 16:49:35 2025 +0800

    fix: fix doubao comment (#766)
    
    * fix doubao comment
    
    * fix doubao comment
    
    * fix doubao comment
    
    * fix doubao comment
    
    * fix doubao comment
    
    * fix unit test
    
    * update ci rule
    
    * revert
---
 .golangci.yaml                                              |  4 ++++
 admin/web/src/utils/common.js                               |  2 +-
 admin/web/src/utils/socket.js                               |  2 +-
 pkg/adapter/dubboregistry/registry/registry.go              |  3 ++-
 pkg/client/dubbo/mapper.go                                  |  2 +-
 pkg/client/dubbo/mapper_test.go                             |  4 ++--
 pkg/client/proxy/reflection.go                              |  3 ++-
 pkg/cluster/loadbalancer/weightrandom/weight_random_test.go |  7 +++++--
 pkg/filter/failinject/filter.go                             | 12 ++++++------
 9 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/.golangci.yaml b/.golangci.yaml
index 7417bdde..4570cfc7 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -10,6 +10,7 @@ linters:
     - ineffassign
     - misspell
     - staticcheck
+    - depguard
   settings:
     depguard:
       rules:
@@ -51,6 +52,9 @@ linters:
       - linters:
           - staticcheck
         text: 'SA1019:'
+      - linters:
+          - staticcheck
+        text: 'QF1008:'
     paths:
       - test/testdata_etc
       - pkg/golinters/goanalysis/(checker|passes)
diff --git a/admin/web/src/utils/common.js b/admin/web/src/utils/common.js
index 60c5ef98..ddc2c9f3 100644
--- a/admin/web/src/utils/common.js
+++ b/admin/web/src/utils/common.js
@@ -109,7 +109,7 @@ export function getDistance (lat1, lng1, lat2, lng2) {
  * @return 返回已拼接的数值
 */
 export function numJoint (val) {
-  if (val) {
+  if (val !== undefined && val !== null && val !== '') {
     val = val.toString()
     // 是否包含小数
     let idx = val.indexOf('.')
diff --git a/admin/web/src/utils/socket.js b/admin/web/src/utils/socket.js
index ceb54a2d..01e4535e 100644
--- a/admin/web/src/utils/socket.js
+++ b/admin/web/src/utils/socket.js
@@ -111,7 +111,7 @@ class socket {
 
     // 发送消息
     send(text) {
-        if (text === 'undefined') return
+        if (text === undefined || text === 'undefined') return;
         if (this._alive === true) {
             text = typeof text === 'string' ? text : JSON.stringify(text)
             this._ws.send(text)
diff --git a/pkg/adapter/dubboregistry/registry/registry.go 
b/pkg/adapter/dubboregistry/registry/registry.go
index d8a8d8ac..48b7f3d7 100644
--- a/pkg/adapter/dubboregistry/registry/registry.go
+++ b/pkg/adapter/dubboregistry/registry/registry.go
@@ -34,6 +34,7 @@ import (
 import (
        common2 
"github.com/apache/dubbo-go-pixiu/pkg/adapter/dubboregistry/common"
        "github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
        "github.com/apache/dubbo-go-pixiu/pkg/model"
 )
 
@@ -85,7 +86,7 @@ func GetRegistry(name string, regConfig model.Registry, 
listener common2.Registr
        if registry, ok := registryMap[regConfig.Protocol]; ok {
                reg, err := registry(regConfig, listener)
                if err != nil {
-                       panic("Initialize Registry" + name + "failed due to: " 
+ err.Error())
+                       logger.Warnf("Initialize Registry %s failed due to: 
%s", name, err.Error())
                }
                return reg, nil
        }
diff --git a/pkg/client/dubbo/mapper.go b/pkg/client/dubbo/mapper.go
index 3ef21ef3..18a60fd6 100644
--- a/pkg/client/dubbo/mapper.go
+++ b/pkg/client/dubbo/mapper.go
@@ -189,7 +189,7 @@ func (um uriMapper) Map(mp config.MappingParam, c 
*client.Request, target any, o
 func validateTarget(target any) (*dubboTarget, error) {
        val, ok := target.(*dubboTarget)
        if !ok {
-               return nil, errors.New("Target params for dubbo backend must be 
*dubbogoTarget")
+               return nil, errors.New("Target params for dubbo backend must be 
*dubboTarget")
        }
        return val, nil
 }
diff --git a/pkg/client/dubbo/mapper_test.go b/pkg/client/dubbo/mapper_test.go
index 16f06576..d43f4efe 100644
--- a/pkg/client/dubbo/mapper_test.go
+++ b/pkg/client/dubbo/mapper_test.go
@@ -224,10 +224,10 @@ func TestValidateTarget(t *testing.T) {
        assert.Nil(t, err)
        assert.NotNil(t, val)
        _, err = validateTarget(*target)
-       assert.EqualError(t, err, "Target params for dubbo backend must be 
*dubbogoTarget")
+       assert.EqualError(t, err, "Target params for dubbo backend must be 
*dubboTarget")
        target2 := ""
        _, err = validateTarget(target2)
-       assert.EqualError(t, err, "Target params for dubbo backend must be 
*dubbogoTarget")
+       assert.EqualError(t, err, "Target params for dubbo backend must be 
*dubboTarget")
 }
 
 func TestMapType(t *testing.T) {
diff --git a/pkg/client/proxy/reflection.go b/pkg/client/proxy/reflection.go
index 166017a5..cf40f9ae 100644
--- a/pkg/client/proxy/reflection.go
+++ b/pkg/client/proxy/reflection.go
@@ -19,6 +19,7 @@ package proxy
 
 import (
        "context"
+       "fmt"
 )
 
 import (
@@ -67,7 +68,7 @@ func (r *Reflector) CreateInvocation(ctx context.Context, 
serviceName, methodNam
 
        methodDesc := serviceDesc.FindMethodByName(methodName)
        if methodDesc == nil {
-               return nil, errors.New("method not found upstream")
+               return nil, fmt.Errorf("method %s not found in service %s 
upstream", methodName, serviceName)
        }
        inputMessage := dynamic.NewMessage(methodDesc.GetInputType())
        err = inputMessage.UnmarshalJSON(input)
diff --git a/pkg/cluster/loadbalancer/weightrandom/weight_random_test.go 
b/pkg/cluster/loadbalancer/weightrandom/weight_random_test.go
index 8a8c2bd5..4ee8b630 100644
--- a/pkg/cluster/loadbalancer/weightrandom/weight_random_test.go
+++ b/pkg/cluster/loadbalancer/weightrandom/weight_random_test.go
@@ -176,14 +176,14 @@ func TestWeightRandom_Handler_Probabilistic(t *testing.T) 
{
                        iterations:       20000,
                },
                {
-                       name:             "some endpoints with default weight",
+                       name:             "some endpoints with default weight 
(y = 1)",
                        endpointsWeights: map[string]int{"x": 2, "y": 1, "z": 
3}, // 'y' will get weight 1
                        expectedProbs:    map[string]float64{"x": 0.33, "y": 
0.17, "z": 0.5},
                        tolerance:        0.04,
                        iterations:       15000,
                },
                {
-                       name:             "some endpoints with default weight",
+                       name:             "some endpoints with zero weight (y = 
0)",
                        endpointsWeights: map[string]int{"x": 2, "y": 0, "z": 
3}, // 'y' will get weight 0
                        expectedProbs:    map[string]float64{"x": 0.4, "y": 0, 
"z": 0.6},
                        tolerance:        0.04,
@@ -212,6 +212,9 @@ func TestWeightRandom_Handler_Probabilistic(t *testing.T) {
                                        t.Errorf("Endpoint %s: expected 
probability %f, got %f (difference %f > tolerance %f)",
                                                id, expectedProb, actualProb, 
diff, tt.tolerance)
                                }
+                               if expectedProb == 0 && counts[id] != 0 {
+                                       t.Errorf("Endpoint %s: expected 0 
selections (weight=0), got %d", id, counts[id])
+                               }
                        }
                })
        }
diff --git a/pkg/filter/failinject/filter.go b/pkg/filter/failinject/filter.go
index 2c065e07..f7a664b3 100644
--- a/pkg/filter/failinject/filter.go
+++ b/pkg/filter/failinject/filter.go
@@ -117,16 +117,16 @@ func (f Filter) match(rule *Rule) (matched bool) {
        if rule == nil {
                return false
        }
-       if rule.TriggerType == TriggerTypeAlways {
+       switch rule.TriggerType {
+       case TriggerTypeAlways:
                return true
-       }
-       if rule.TriggerType == TriggerTypePercentage {
+       case TriggerTypePercentage:
                return percentage(rule.Odds)
-       }
-       if rule.TriggerType == TriggerTypeRandom {
+       case TriggerTypeRandom:
                return random()
+       default:
+               return false
        }
-       return false
 }
 
 // random if the current request is matched

Reply via email to