Skip to content

Commit

Permalink
Revert "dev: update route"
Browse files Browse the repository at this point in the history
This reverts commit 5bd16449d888c50b1842fb98a711c07944351a6c.
  • Loading branch information
zhangxu19830126 committed Feb 22, 2019
1 parent 18d4e18 commit e9d4764
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 92 deletions.
7 changes: 0 additions & 7 deletions cmd/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ func main() {
return c.String(http.StatusOK, "OK")
})

server.GET("/header", func(c echo.Context) error {
if c.Request().Header.Get("Token") == "" {
return c.String(http.StatusOK, "missing token")
}
return c.String(http.StatusOK, "OK")
})

server.GET("/check", func(c echo.Context) error {
return c.String(http.StatusOK, "OK")
})
Expand Down
41 changes: 0 additions & 41 deletions pkg/route/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,6 @@ import (
"fmt"
)

type nodeType int

const (
slashType = nodeType(1)
constType = nodeType(2)
numberType = nodeType(3)
stringType = nodeType(4)
enumType = nodeType(5)
)

type node struct {
nt nodeType
value []byte
enums [][]byte
argName []byte
}

func (n *node) matches(target *node) bool {
if n.nt != target.nt {
return false
}

return bytes.Equal(n.value, target.value)
}

func (n *node) isEnum() bool {
return n.nt == enumType
}

func (n *node) isConst() bool {
return n.nt == constType
}

func (n *node) addEnum(value []byte) {
n.enums = append(n.enums, value)
}

func (n *node) setArgName(value []byte) {
n.argName = value
}

type parser struct {
nodes []node
input []byte
Expand Down
49 changes: 33 additions & 16 deletions pkg/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,49 @@ package route

import (
"github.com/fagongzi/gateway/pkg/pb/metapb"
"github.com/fagongzi/util/hack"
)

type nodeType int

const (
slashType = nodeType(1)
constType = nodeType(2)
numberType = nodeType(3)
stringType = nodeType(4)
enumType = nodeType(5)
)

// Route route for api match
// url define: /conststring/(number|string|enum:m1|m2|m3)[:argname]
type Route struct {
root node
root *node
}

type node struct {
nt nodeType
value []byte
enums [][]byte
argName []byte
children []node
}

func (n *node) isEnum() bool {
return n.nt == enumType
}

func (n *node) isConst() bool {
return n.nt == constType
}

// NewRoute create a api match route
func NewRoute() *Route {
return &Route{
root: node{
nt: slashType,
value: slashValue,
},
}
func (n *node) addEnum(value []byte) {
n.enums = append(n.enums, value)
}

func (n *node) setArgName(value []byte) {
n.argName = value
}

// Add add a url to this route
func (r *Route) Add(api metapb.API) error {
p := newParser(hack.StringToSlice(api.URLPattern))
_, err := p.parse()
if err != nil {
return err
}

return nil
}
27 changes: 0 additions & 27 deletions pkg/route/route_tree.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/route/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestNext(t *testing.T) {
}

s.Next()
ch = s.Current()
if ch != eoi {
t.Errorf("ch expect eoi but %c", ch)
}
Expand Down

0 comments on commit e9d4764

Please sign in to comment.