Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
54ba307f
authored
2014-11-05 22:40:31 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
change this to short name
1 parent
950ff91d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
44 deletions
example/beeapi/controllers/default.go
example/chat/controllers/default.go
example/chat/controllers/ws.go
flash_test.go
router_test.go
example/beeapi/controllers/default.go
View file @
54ba307
...
...
@@ -17,47 +17,47 @@ type ObjectController struct {
beego
.
Controller
}
func
(
this
*
ObjectController
)
Post
()
{
func
(
o
*
ObjectController
)
Post
()
{
var
ob
models
.
Object
json
.
Unmarshal
(
this
.
Ctx
.
Input
.
RequestBody
,
&
ob
)
json
.
Unmarshal
(
o
.
Ctx
.
Input
.
RequestBody
,
&
ob
)
objectid
:=
models
.
AddOne
(
ob
)
this
.
Data
[
"json"
]
=
map
[
string
]
string
{
"ObjectId"
:
objectid
}
this
.
ServeJson
()
o
.
Data
[
"json"
]
=
map
[
string
]
string
{
"ObjectId"
:
objectid
}
o
.
ServeJson
()
}
func
(
this
*
ObjectController
)
Get
()
{
objectId
:=
this
.
Ctx
.
Input
.
Params
[
":objectId"
]
func
(
o
*
ObjectController
)
Get
()
{
objectId
:=
o
.
Ctx
.
Input
.
Params
[
":objectId"
]
if
objectId
!=
""
{
ob
,
err
:=
models
.
GetOne
(
objectId
)
if
err
!=
nil
{
this
.
Data
[
"json"
]
=
err
o
.
Data
[
"json"
]
=
err
}
else
{
this
.
Data
[
"json"
]
=
ob
o
.
Data
[
"json"
]
=
ob
}
}
else
{
obs
:=
models
.
GetAll
()
this
.
Data
[
"json"
]
=
obs
o
.
Data
[
"json"
]
=
obs
}
this
.
ServeJson
()
o
.
ServeJson
()
}
func
(
this
*
ObjectController
)
Put
()
{
objectId
:=
this
.
Ctx
.
Input
.
Params
[
":objectId"
]
func
(
o
*
ObjectController
)
Put
()
{
objectId
:=
o
.
Ctx
.
Input
.
Params
[
":objectId"
]
var
ob
models
.
Object
json
.
Unmarshal
(
this
.
Ctx
.
Input
.
RequestBody
,
&
ob
)
json
.
Unmarshal
(
o
.
Ctx
.
Input
.
RequestBody
,
&
ob
)
err
:=
models
.
Update
(
objectId
,
ob
.
Score
)
if
err
!=
nil
{
this
.
Data
[
"json"
]
=
err
o
.
Data
[
"json"
]
=
err
}
else
{
this
.
Data
[
"json"
]
=
"update success!"
o
.
Data
[
"json"
]
=
"update success!"
}
this
.
ServeJson
()
o
.
ServeJson
()
}
func
(
this
*
ObjectController
)
Delete
()
{
objectId
:=
this
.
Ctx
.
Input
.
Params
[
":objectId"
]
func
(
o
*
ObjectController
)
Delete
()
{
objectId
:=
o
.
Ctx
.
Input
.
Params
[
":objectId"
]
models
.
Delete
(
objectId
)
this
.
Data
[
"json"
]
=
"delete success!"
this
.
ServeJson
()
o
.
Data
[
"json"
]
=
"delete success!"
o
.
ServeJson
()
}
...
...
example/chat/controllers/default.go
View file @
54ba307
...
...
@@ -14,7 +14,7 @@ type MainController struct {
beego
.
Controller
}
func
(
this
*
MainController
)
Get
()
{
this
.
Data
[
"host"
]
=
this
.
Ctx
.
Request
.
Host
this
.
TplNames
=
"index.tpl"
func
(
m
*
MainController
)
Get
()
{
m
.
Data
[
"host"
]
=
m
.
Ctx
.
Request
.
Host
m
.
TplNames
=
"index.tpl"
}
...
...
example/chat/controllers/ws.go
View file @
54ba307
...
...
@@ -154,10 +154,10 @@ var upgrader = websocket.Upgrader{
WriteBufferSize
:
1024
,
}
func
(
this
*
WSController
)
Get
()
{
ws
,
err
:=
upgrader
.
Upgrade
(
this
.
Ctx
.
ResponseWriter
,
this
.
Ctx
.
Request
,
nil
)
func
(
w
*
WSController
)
Get
()
{
ws
,
err
:=
upgrader
.
Upgrade
(
w
.
Ctx
.
ResponseWriter
,
w
.
Ctx
.
Request
,
nil
)
if
_
,
ok
:=
err
.
(
websocket
.
HandshakeError
);
ok
{
http
.
Error
(
this
.
Ctx
.
ResponseWriter
,
"Not a websocket handshake"
,
400
)
http
.
Error
(
w
.
Ctx
.
ResponseWriter
,
"Not a websocket handshake"
,
400
)
return
}
else
if
err
!=
nil
{
return
...
...
flash_test.go
View file @
54ba307
...
...
@@ -25,12 +25,12 @@ type TestFlashController struct {
Controller
}
func
(
t
his
*
TestFlashController
)
TestWriteFlash
()
{
func
(
t
*
TestFlashController
)
TestWriteFlash
()
{
flash
:=
NewFlash
()
flash
.
Notice
(
"TestFlashString"
)
flash
.
Store
(
&
t
his
.
Controller
)
flash
.
Store
(
&
t
.
Controller
)
// we choose to serve json because we don't want to load a template html file
t
his
.
ServeJson
(
true
)
t
.
ServeJson
(
true
)
}
func
TestFlashHeader
(
t
*
testing
.
T
)
{
...
...
router_test.go
View file @
54ba307
...
...
@@ -27,33 +27,33 @@ type TestController struct {
Controller
}
func
(
t
his
*
TestController
)
Get
()
{
t
his
.
Data
[
"Username"
]
=
"astaxie"
t
his
.
Ctx
.
Output
.
Body
([]
byte
(
"ok"
))
func
(
t
c
*
TestController
)
Get
()
{
t
c
.
Data
[
"Username"
]
=
"astaxie"
t
c
.
Ctx
.
Output
.
Body
([]
byte
(
"ok"
))
}
func
(
t
his
*
TestController
)
Post
()
{
t
his
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
Ctx
.
Input
.
Query
(
":name"
)))
func
(
t
c
*
TestController
)
Post
()
{
t
c
.
Ctx
.
Output
.
Body
([]
byte
(
tc
.
Ctx
.
Input
.
Query
(
":name"
)))
}
func
(
t
his
*
TestController
)
Param
()
{
t
his
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
Ctx
.
Input
.
Query
(
":name"
)))
func
(
t
c
*
TestController
)
Param
()
{
t
c
.
Ctx
.
Output
.
Body
([]
byte
(
tc
.
Ctx
.
Input
.
Query
(
":name"
)))
}
func
(
t
his
*
TestController
)
List
()
{
t
his
.
Ctx
.
Output
.
Body
([]
byte
(
"i am list"
))
func
(
t
c
*
TestController
)
List
()
{
t
c
.
Ctx
.
Output
.
Body
([]
byte
(
"i am list"
))
}
func
(
t
his
*
TestController
)
Params
()
{
t
his
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
Ctx
.
Input
.
Params
[
"0"
]
+
this
.
Ctx
.
Input
.
Params
[
"1"
]
+
this
.
Ctx
.
Input
.
Params
[
"2"
]))
func
(
t
c
*
TestController
)
Params
()
{
t
c
.
Ctx
.
Output
.
Body
([]
byte
(
tc
.
Ctx
.
Input
.
Params
[
"0"
]
+
tc
.
Ctx
.
Input
.
Params
[
"1"
]
+
tc
.
Ctx
.
Input
.
Params
[
"2"
]))
}
func
(
t
his
*
TestController
)
Myext
()
{
t
his
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
Ctx
.
Input
.
Param
(
":ext"
)))
func
(
t
c
*
TestController
)
Myext
()
{
t
c
.
Ctx
.
Output
.
Body
([]
byte
(
tc
.
Ctx
.
Input
.
Param
(
":ext"
)))
}
func
(
t
his
*
TestController
)
GetUrl
()
{
t
his
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
UrlFor
(
".Myext"
)))
func
(
t
c
*
TestController
)
GetUrl
()
{
t
c
.
Ctx
.
Output
.
Body
([]
byte
(
tc
.
UrlFor
(
".Myext"
)))
}
func
(
t
*
TestController
)
GetParams
()
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment