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

xiaoliu 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 da865b0  Fix reviewdog (#195)
da865b0 is described below

commit da865b0674b94090bbff092af35ab9096df95820
Author: randy <[email protected]>
AuthorDate: Thu Jul 1 09:23:40 2021 +0800

    Fix reviewdog (#195)
    
    * fix reviewdog problem
    
    * fix ci
    
    * lowercase path key
    
    Co-authored-by: kezhenxu94 <[email protected]>
---
 pkg/config/api_config.go                  | 12 ++++--------
 pkg/pixiu/pixiu_start.go                  |  4 +++-
 pkg/service/api/discovery_service.go      |  4 ++--
 pkg/service/api/discovery_service_test.go |  4 ++--
 4 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/pkg/config/api_config.go b/pkg/config/api_config.go
index d7b4e44..a23285f 100644
--- a/pkg/config/api_config.go
+++ b/pkg/config/api_config.go
@@ -142,7 +142,7 @@ func initAPIConfigFromKVList(kList, vList []string) error {
 }
 
 func initAPIConfigMethodFromKvList(config *fc.APIConfig, kList, vList 
[]string) error {
-       for i, _ := range kList {
+       for i := range kList {
                v := vList[i]
                method := &fc.Method{}
                err := yaml.UnmarshalYML([]byte(v), method)
@@ -183,7 +183,7 @@ func initAPIConfigMethodFromKvList(config *fc.APIConfig, 
kList, vList []string)
 }
 
 func initAPIConfigServiceFromKvList(config *fc.APIConfig, kList, vList 
[]string) error {
-       for i, _ := range kList {
+       for i := range kList {
                v := vList[i]
                resource := &fc.Resource{}
                err := yaml.UnmarshalYML([]byte(v), resource)
@@ -401,16 +401,12 @@ func mergeApiConfigMethod(path string, val fc.Method) {
        }
 }
 
-func getCheckBaseInfoRegexp() *regexp.Regexp {
-       return regexp.MustCompile(".+/base$")
-}
-
 func getCheckResourceRegexp() *regexp.Regexp {
-       return regexp.MustCompile(".+/Resources/[^/]+/?$")
+       return regexp.MustCompile(".+/resources/[^/]+/?$")
 }
 
 func getExtractMethodRegexp() *regexp.Regexp {
-       return regexp.MustCompile("Resources/([^/]+)/Method/[^/]+/?$")
+       return regexp.MustCompile("resources/([^/]+)/method/[^/]+/?$")
 }
 
 // RegisterConfigListener register APIConfigListener
diff --git a/pkg/pixiu/pixiu_start.go b/pkg/pixiu/pixiu_start.go
index d5e53c4..1fd0918 100644
--- a/pkg/pixiu/pixiu_start.go
+++ b/pkg/pixiu/pixiu_start.go
@@ -78,7 +78,9 @@ func (p *PX) Start() {
 func (p *PX) beforeStart() {
        dubbo.SingletonDubboClient().Init()
        initialize.Run(config.GetAPIConf())
-       api.InitAPIsFromConfig(config.GetAPIConf())
+       if err := api.InitAPIsFromConfig(config.GetAPIConf()); err != nil {
+               logger.Errorf("InitAPIsFromConfig fail: %v", err)
+       }
 }
 
 // NewPX create pixiu
diff --git a/pkg/service/api/discovery_service.go 
b/pkg/service/api/discovery_service.go
index 42e3720..0042b6a 100644
--- a/pkg/service/api/discovery_service.go
+++ b/pkg/service/api/discovery_service.go
@@ -207,7 +207,7 @@ func deleteAPIFromResource(old config.Resource, localSrv 
service.APIDiscoverySer
 func addAPIFromResource(resource config.Resource, localSrv 
service.APIDiscoveryService, groupPath string, parentPath string, fullHeaders 
map[string]string) error {
        fullPath := getFullPath(groupPath, resource.Path)
        if !strings.HasPrefix(resource.Path, constant.PathSlash) {
-               return errors.New(fmt.Sprintf("Path %s in %s doesn't start with 
/", resource.Path, parentPath))
+               return fmt.Errorf("path %s in %s doesn't start with /", 
resource.Path, parentPath)
        }
        for headerName, headerValue := range resource.Headers {
                fullHeaders[headerName] = headerValue
@@ -231,7 +231,7 @@ func addAPIFromMethod(fullPath string, method 
config.Method, headers map[string]
                Headers:    headers,
        }
        if err := localSrv.AddAPI(api); err != nil {
-               return errors.New(fmt.Sprintf("Path: %s, Method: %s, error: 
%s", fullPath, method.HTTPVerb, err.Error()))
+               return fmt.Errorf("path: %s, Method: %s, error: %s", fullPath, 
method.HTTPVerb, err.Error())
        }
        return nil
 }
diff --git a/pkg/service/api/discovery_service_test.go 
b/pkg/service/api/discovery_service_test.go
index 9fcd527..8534a1d 100644
--- a/pkg/service/api/discovery_service_test.go
+++ b/pkg/service/api/discovery_service_test.go
@@ -166,7 +166,7 @@ func TestLoadAPIFromResource(t *testing.T) {
        }
        apiDiscSrv = NewLocalMemoryAPIDiscoveryService()
        err = loadAPIFromResource("", tempResources, nil, apiDiscSrv)
-       assert.EqualError(t, err, "Path :id in /mock doesn't start with /; Path 
:ik in /mock doesn't start with /")
+       assert.EqualError(t, err, "path :id in /mock doesn't start with /; path 
:ik in /mock doesn't start with /")
 }
 
 func TestLoadAPIFromMethods(t *testing.T) {
@@ -181,5 +181,5 @@ func TestLoadAPIFromMethods(t *testing.T) {
        assert.Equal(t, rsp.URLPattern, "/mock")
        rsp, _ = apiDiscSrv.GetAPI("/mock", fc.MethodGet)
        assert.Equal(t, rsp.URLPattern, "/mock")
-       assert.EqualError(t, err, "Path: /mock, Method: PUT, error: Method PUT 
already exists in path /mock")
+       assert.EqualError(t, err, "path: /mock, Method: PUT, error: Method PUT 
already exists in path /mock")
 }

Reply via email to