Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
62e528ca
Commit
62e528ca
authored
Sep 08, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
golint tree.go
parent
bcb1db25
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
14 deletions
+17
-14
tree.go
tree.go
+17
-14
No files found.
tree.go
View file @
62e528ca
...
...
@@ -22,6 +22,10 @@ import (
"github.com/astaxie/beego/utils"
)
// Tree has three elements: FixRouter/wildcard/leaves
// fixRouter sotres Fixed Router
// wildcard stores params
// leaves store the endpoint information
type
Tree
struct
{
//search fix route first
fixrouters
map
[
string
]
*
Tree
...
...
@@ -33,13 +37,14 @@ type Tree struct {
leaves
[]
*
leafInfo
}
// NewTree return a new Tree
func
NewTree
()
*
Tree
{
return
&
Tree
{
fixrouters
:
make
(
map
[
string
]
*
Tree
),
}
}
//
add T
ree to the exist Tree
//
AddTree will add t
ree to the exist Tree
// prefix should has no params
func
(
t
*
Tree
)
AddTree
(
prefix
string
,
tree
*
Tree
)
{
t
.
addtree
(
splitPath
(
prefix
),
tree
,
nil
,
""
)
...
...
@@ -187,7 +192,7 @@ func filterTreeWithPrefix(t *Tree, wildcards []string, reg string) {
}
}
// call addseg function
//
AddRouter
call addseg function
func
(
t
*
Tree
)
AddRouter
(
pattern
string
,
runObject
interface
{})
{
t
.
addseg
(
splitPath
(
pattern
),
runObject
,
nil
,
""
)
}
...
...
@@ -266,7 +271,7 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
}
}
//
m
atch router to runObject & params
//
M
atch router to runObject & params
func
(
t
*
Tree
)
Match
(
pattern
string
)
(
runObject
interface
{},
params
map
[
string
]
string
)
{
if
len
(
pattern
)
==
0
||
pattern
[
0
]
!=
'/'
{
return
nil
,
nil
...
...
@@ -349,7 +354,7 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string
continue
}
params
[
v
]
=
""
j
+=
1
j
++
}
return
true
,
params
}
...
...
@@ -402,7 +407,7 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string
return
false
,
nil
}
params
[
v
]
=
wildcardValues
[
j
]
j
+=
1
j
++
}
if
len
(
params
)
!=
len
(
wildcardValues
)
{
return
false
,
nil
...
...
@@ -453,9 +458,8 @@ func splitSegment(key string) (bool, []string, string) {
if
strings
.
HasPrefix
(
key
,
"*"
)
{
if
key
==
"*.*"
{
return
true
,
[]
string
{
"."
,
":path"
,
":ext"
},
""
}
else
{
return
true
,
[]
string
{
":splat"
},
""
}
return
true
,
[]
string
{
":splat"
},
""
}
if
strings
.
ContainsAny
(
key
,
":"
)
{
var
paramsNum
int
...
...
@@ -469,7 +473,7 @@ func splitSegment(key string) (bool, []string, string) {
reg
:=
regexp
.
MustCompile
(
`[a-zA-Z0-9_]+`
)
for
i
,
v
:=
range
key
{
if
skipnum
>
0
{
skipnum
-=
1
skipnum
--
continue
}
if
start
{
...
...
@@ -483,7 +487,7 @@ func splitSegment(key string) (bool, []string, string) {
startexp
=
false
skipnum
=
3
param
=
make
([]
rune
,
0
)
paramsNum
+=
1
paramsNum
++
continue
}
}
...
...
@@ -491,7 +495,7 @@ func splitSegment(key string) (bool, []string, string) {
if
key
[
i
+
1
:
i
+
7
]
==
"string"
{
out
=
append
(
out
,
[]
rune
(
`([\w]+)`
)
...
)
params
=
append
(
params
,
":"
+
string
(
param
))
paramsNum
+=
1
paramsNum
++
start
=
false
startexp
=
false
skipnum
=
6
...
...
@@ -509,7 +513,7 @@ func splitSegment(key string) (bool, []string, string) {
out
=
append
(
out
,
[]
rune
(
`(.+)`
)
...
)
params
=
append
(
params
,
":"
+
string
(
param
))
param
=
make
([]
rune
,
0
)
paramsNum
+=
1
paramsNum
++
start
=
false
startexp
=
false
}
...
...
@@ -527,7 +531,7 @@ func splitSegment(key string) (bool, []string, string) {
startexp
=
true
start
=
false
params
=
append
(
params
,
":"
+
string
(
param
))
paramsNum
+=
1
paramsNum
++
expt
=
make
([]
rune
,
0
)
expt
=
append
(
expt
,
'('
)
}
else
if
v
==
')'
{
...
...
@@ -548,7 +552,6 @@ func splitSegment(key string) (bool, []string, string) {
params
=
append
(
params
,
":"
+
string
(
param
))
}
return
true
,
params
,
string
(
out
)
}
else
{
return
false
,
nil
,
""
}
return
false
,
nil
,
""
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment