Skip to content

Commit

Permalink
Merge branch 'develop' into add_more_test_case
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoliu10 committed Jul 11, 2021
2 parents d5f1421 + 2ced699 commit 2c9e62e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions pkg/router/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ func (rt *Route) ClearAPI() error {

// PutAPI puts an api into the resource
func (rt *Route) PutAPI(api router.API) error {
lowerCasePath := strings.ToLower(api.URLPattern)
node, ok := rt.findNode(lowerCasePath)
fullPath := api.URLPattern
node, ok := rt.findNode(fullPath)
rt.lock.Lock()
defer rt.lock.Unlock()
if !ok {
wildcard := strings.Contains(lowerCasePath, constant.PathParamIdentifier)
wildcard := strings.Contains(fullPath, constant.PathParamIdentifier)
rn := &Node{
fullPath: lowerCasePath,
fullPath: fullPath,
methods: map[config.HTTPVerb]*config.Method{api.Method.HTTPVerb: &api.Method},
wildcard: wildcard,
headers: api.Headers,
}
if wildcard {
rt.wildcardTree.Put(lowerCasePath, rn)
rt.wildcardTree.Put(fullPath, rn)
}
rt.tree.Put(lowerCasePath, rn)
rt.tree.Put(fullPath, rn)
return nil
}
return node.putMethod(api.Method, api.Headers)
Expand Down Expand Up @@ -122,10 +122,9 @@ func (rt *Route) FindAPI(fullPath string, httpverb config.HTTPVerb) (*router.API

// DeleteNode delete node by fullPath
func (rt *Route) DeleteNode(fullPath string) bool {
lowerPath := strings.ToLower(fullPath)
rt.lock.RLock()
defer rt.lock.RUnlock()
rt.tree.Remove(lowerPath)
rt.tree.Remove(fullPath)
return true
}

Expand All @@ -141,13 +140,12 @@ func (rt *Route) DeleteAPI(fullPath string, httpverb config.HTTPVerb) bool {
}

func (rt *Route) findNode(fullPath string) (*Node, bool) {
lowerPath := strings.ToLower(fullPath)
var n interface{}
var found bool
if n, found = rt.searchWildcard(lowerPath); !found {
if n, found = rt.searchWildcard(fullPath); !found {
rt.lock.RLock()
defer rt.lock.RUnlock()
if n, found = rt.tree.Get(lowerPath); !found {
if n, found = rt.tree.Get(fullPath); !found {
return nil, false
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/plugins/ratelimit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resources:
- enable: true
flowRule:
#the resource's name
resource: "test-dubbo"
resource: "test-http"
threshold: 100
statintervalinms: 1000
```
Expand Down
2 changes: 1 addition & 1 deletion samples/plugins/ratelimit/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resources:
- enable: true
flowRule:
#the resource's name
resource: "test-dubbo"
resource: "test-http"
threshold: 100
statintervalinms: 1000
```
Expand Down

0 comments on commit 2c9e62e

Please sign in to comment.