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
2f02653b
Commit
2f02653b
authored
Apr 09, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add GetFIle & enhance router
parent
f9e8b4f1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
controller.go
controller.go
+5
-0
router.go
router.go
+27
-3
No files found.
controller.go
View file @
2f02653b
...
...
@@ -7,6 +7,7 @@ import (
"github.com/astaxie/beego/session"
"html/template"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
"path"
...
...
@@ -191,6 +192,10 @@ func (c *Controller) GetBool(key string) (bool, error) {
return
strconv
.
ParseBool
(
c
.
Input
()
.
Get
(
key
))
}
func
(
c
*
Controller
)
GetFile
(
key
string
)
(
multipart
.
File
,
*
multipart
.
FileHeader
,
error
)
{
return
c
.
Ctx
.
Request
.
FormFile
(
key
)
}
func
(
c
*
Controller
)
StartSession
()
(
sess
session
.
SessionStore
)
{
sess
=
GlobalSessions
.
SessionStart
(
c
.
Ctx
.
ResponseWriter
,
c
.
Ctx
.
Request
)
return
...
...
router.go
View file @
2f02653b
...
...
@@ -41,17 +41,43 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface) {
params
:=
make
(
map
[
int
]
string
)
for
i
,
part
:=
range
parts
{
if
strings
.
HasPrefix
(
part
,
":"
)
{
expr
:=
"(
[^/]
+)"
expr
:=
"(
.
+)"
//a user may choose to override the defult expression
// similar to expressjs: ‘/user/:id([0-9]+)’
if
index
:=
strings
.
Index
(
part
,
"("
);
index
!=
-
1
{
expr
=
part
[
index
:
]
part
=
part
[
:
index
]
//match /user/:id:int ([0-9]+)
//match /post/:username:word ([\w]+)
}
else
if
lindex
:=
strings
.
LastIndex
(
part
,
":"
);
lindex
!=
0
{
switch
part
[
lindex
:
]
{
case
"int"
:
expr
=
"([0-9]+)"
part
=
part
[
:
index
]
case
"word"
:
expr
=
`([\w]+)`
part
=
part
[
:
index
]
}
}
params
[
j
]
=
part
parts
[
i
]
=
expr
j
++
}
if
strings
.
HasPrefix
(
part
,
"*"
)
{
expr
:=
"(.+)"
if
part
==
"*.*"
{
params
[
j
]
=
":path"
parts
[
j
]
=
"([^.]+)."
j
++
params
[
j
]
=
":ext"
parts
[
j
]
=
"([^.]+)"
j
++
}
else
{
params
[
j
]
=
":splat"
parts
[
i
]
=
expr
j
++
}
}
}
if
j
==
0
{
//now create the Route
...
...
@@ -79,10 +105,8 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface) {
route
.
params
=
params
route
.
pattern
=
pattern
route
.
controllerType
=
t
p
.
routers
=
append
(
p
.
routers
,
route
)
}
}
func
(
p
*
ControllerRegistor
)
AddHandler
(
pattern
string
,
c
http
.
Handler
)
{
...
...
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