Skip to content

Commit

Permalink
Fix reviewdog (apache#195)
Browse files Browse the repository at this point in the history
* fix reviewdog problem

* fix ci

* lowercase path key

Co-authored-by: kezhenxu94 <[email protected]>
  • Loading branch information
ztelur and kezhenxu94 authored Jul 1, 2021
1 parent cc1c7e2 commit 8c7e353
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
12 changes: 4 additions & 8 deletions pkg/config/api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/pixiu/pixiu_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/api/discovery_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/api/discovery_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}

0 comments on commit 8c7e353

Please sign in to comment.