Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use bytes.Equal instead bytes.Compare #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/proxy/filter_cross_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (f *CrossDomainFilter) Name() string {

// Pre execute before proxy
func (f *CrossDomainFilter) Pre(c filter.Context) (statusCode int, err error) {
if bytes.Compare(c.OriginRequest().Method(), options) != 0 {
if !bytes.Equal(c.OriginRequest().Method(), options) {
return f.BaseFilter.Pre(c)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/route/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (n *node) isMatchAllConstString() bool {
func (n *node) inEnumValue(value []byte) bool {
in := false
for _, enum := range n.enums {
if bytes.Compare(enum, value) == 0 {
if bytes.Equal(enum, value) {
in = true
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (item *routeItem) urlMatches(n node, matchAllParam *bytes.Buffer) bool {
return true
}

return bytes.Compare(item.node.value, n.value) == 0
return bytes.Equal(item.node.value, n.value)
case stringType:
return true
default:
Expand All @@ -75,7 +75,7 @@ func (item *routeItem) matches(n node) bool {
case stringType:
return true
case constType:
return bytes.Compare(item.node.value, n.value) == 0
return bytes.Equal(item.node.value, n.value)
case enumType:
return true
default:
Expand Down
12 changes: 6 additions & 6 deletions pkg/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ func TestFindMatchAll(t *testing.T) {
if id != 1 {
t.Errorf("expect matched 1, but %d", id)
}
if bytes.Compare(params["*"], []byte("p1")) != 0 {
if !bytes.Equal(params["*"], []byte("p1")) {
t.Errorf("expect params p1, but %s", params["*"])
}

id, _ = r.Find([]byte("/p1/p2"), "GET", paramsFunc)
if id != 1 {
t.Errorf("expect matched 1, but %d", id)
}
if bytes.Compare(params["*"], []byte("p1/p2")) != 0 {
if !bytes.Equal(params["*"], []byte("p1/p2")) {
t.Errorf("expect params p1/p2, but %s", params["*"])
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestFind(t *testing.T) {
if id != 3 {
t.Errorf("expect matched 3, but %d", id)
}
if bytes.Compare(params["name"], []byte("check2")) != 0 {
if !bytes.Equal(params["name"], []byte("check2")) {
t.Errorf("expect params check2, but %s", params["name"])
}

Expand All @@ -310,7 +310,7 @@ func TestFind(t *testing.T) {
if id != 4 {
t.Errorf("expect matched 4, but %d", id)
}
if bytes.Compare(params["age"], []byte("123")) != 0 {
if !bytes.Equal(params["age"], []byte("123")) {
t.Errorf("expect params 123, but %s", params["age"])
}

Expand All @@ -319,7 +319,7 @@ func TestFind(t *testing.T) {
if id != 5 {
t.Errorf("expect matched 5, but %d", id)
}
if bytes.Compare(params["action"], []byte("on")) != 0 {
if !bytes.Equal(params["action"], []byte("on")) {
t.Errorf("expect params on, but %s", params["action"])
}

Expand All @@ -328,7 +328,7 @@ func TestFind(t *testing.T) {
if id != 5 {
t.Errorf("expect matched 5, but %d", id)
}
if bytes.Compare(params["action"], []byte("off")) != 0 {
if !bytes.Equal(params["action"], []byte("off")) {
t.Errorf("expect params off, but %s", params["action"])
}

Expand Down