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
01a5e542
Commit
01a5e542
authored
Sep 10, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete example from the source code
parent
ff5b09fc
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
0 additions
and
469 deletions
+0
-469
app.conf
example/beeapi/conf/app.conf
+0
-5
default.go
example/beeapi/controllers/default.go
+0
-63
main.go
example/beeapi/main.go
+0
-30
object.go
example/beeapi/models/object.go
+0
-58
app.conf
example/chat/conf/app.conf
+0
-3
default.go
example/chat/controllers/default.go
+0
-20
ws.go
example/chat/controllers/ws.go
+0
-180
main.go
example/chat/main.go
+0
-17
index.tpl
example/chat/views/index.tpl
+0
-93
No files found.
example/beeapi/conf/app.conf
deleted
100644 → 0
View file @
ff5b09fc
appname
=
beeapi
httpport
=
8080
runmode
=
dev
autorender
=
false
copyrequestbody
=
true
example/beeapi/controllers/default.go
deleted
100644 → 0
View file @
ff5b09fc
// Beego (http://beego.me/)
// @description beego is an open-source, high-performance web framework for the Go programming language.
// @link http://github.com/astaxie/beego for the canonical source repository
// @license http://github.com/astaxie/beego/blob/master/LICENSE
// @authors astaxie
package
controllers
import
(
"encoding/json"
"github.com/astaxie/beego"
"github.com/astaxie/beego/example/beeapi/models"
)
type
ObjectController
struct
{
beego
.
Controller
}
func
(
o
*
ObjectController
)
Post
()
{
var
ob
models
.
Object
json
.
Unmarshal
(
o
.
Ctx
.
Input
.
RequestBody
,
&
ob
)
objectid
:=
models
.
AddOne
(
ob
)
o
.
Data
[
"json"
]
=
map
[
string
]
string
{
"ObjectId"
:
objectid
}
o
.
ServeJson
()
}
func
(
o
*
ObjectController
)
Get
()
{
objectId
:=
o
.
Ctx
.
Input
.
Params
[
":objectId"
]
if
objectId
!=
""
{
ob
,
err
:=
models
.
GetOne
(
objectId
)
if
err
!=
nil
{
o
.
Data
[
"json"
]
=
err
}
else
{
o
.
Data
[
"json"
]
=
ob
}
}
else
{
obs
:=
models
.
GetAll
()
o
.
Data
[
"json"
]
=
obs
}
o
.
ServeJson
()
}
func
(
o
*
ObjectController
)
Put
()
{
objectId
:=
o
.
Ctx
.
Input
.
Params
[
":objectId"
]
var
ob
models
.
Object
json
.
Unmarshal
(
o
.
Ctx
.
Input
.
RequestBody
,
&
ob
)
err
:=
models
.
Update
(
objectId
,
ob
.
Score
)
if
err
!=
nil
{
o
.
Data
[
"json"
]
=
err
}
else
{
o
.
Data
[
"json"
]
=
"update success!"
}
o
.
ServeJson
()
}
func
(
o
*
ObjectController
)
Delete
()
{
objectId
:=
o
.
Ctx
.
Input
.
Params
[
":objectId"
]
models
.
Delete
(
objectId
)
o
.
Data
[
"json"
]
=
"delete success!"
o
.
ServeJson
()
}
example/beeapi/main.go
deleted
100644 → 0
View file @
ff5b09fc
// Beego (http://beego.me/)
// @description beego is an open-source, high-performance web framework for the Go programming language.
// @link http://github.com/astaxie/beego for the canonical source repository
// @license http://github.com/astaxie/beego/blob/master/LICENSE
// @authors astaxie
package
main
import
(
"github.com/astaxie/beego"
"github.com/astaxie/beego/example/beeapi/controllers"
)
// Objects
// URL HTTP Verb Functionality
// /object POST Creating Objects
// /object/<objectId> GET Retrieving Objects
// /object/<objectId> PUT Updating Objects
// /object GET Queries
// /object/<objectId> DELETE Deleting Objects
func
main
()
{
beego
.
RESTRouter
(
"/object"
,
&
controllers
.
ObjectController
{})
beego
.
Run
()
}
example/beeapi/models/object.go
deleted
100644 → 0
View file @
ff5b09fc
// Beego (http://beego.me/)
// @description beego is an open-source, high-performance web framework for the Go programming language.
// @link http://github.com/astaxie/beego for the canonical source repository
// @license http://github.com/astaxie/beego/blob/master/LICENSE
// @authors astaxie
package
models
import
(
"errors"
"strconv"
"time"
)
var
(
Objects
map
[
string
]
*
Object
)
type
Object
struct
{
ObjectId
string
Score
int64
PlayerName
string
}
func
init
()
{
Objects
=
make
(
map
[
string
]
*
Object
)
Objects
[
"hjkhsbnmn123"
]
=
&
Object
{
"hjkhsbnmn123"
,
100
,
"astaxie"
}
Objects
[
"mjjkxsxsaa23"
]
=
&
Object
{
"mjjkxsxsaa23"
,
101
,
"someone"
}
}
func
AddOne
(
object
Object
)
(
ObjectId
string
)
{
object
.
ObjectId
=
"astaxie"
+
strconv
.
FormatInt
(
time
.
Now
()
.
UnixNano
(),
10
)
Objects
[
object
.
ObjectId
]
=
&
object
return
object
.
ObjectId
}
func
GetOne
(
ObjectId
string
)
(
object
*
Object
,
err
error
)
{
if
v
,
ok
:=
Objects
[
ObjectId
];
ok
{
return
v
,
nil
}
return
nil
,
errors
.
New
(
"ObjectId Not Exist"
)
}
func
GetAll
()
map
[
string
]
*
Object
{
return
Objects
}
func
Update
(
ObjectId
string
,
Score
int64
)
(
err
error
)
{
if
v
,
ok
:=
Objects
[
ObjectId
];
ok
{
v
.
Score
=
Score
return
nil
}
return
errors
.
New
(
"ObjectId Not Exist"
)
}
func
Delete
(
ObjectId
string
)
{
delete
(
Objects
,
ObjectId
)
}
example/chat/conf/app.conf
deleted
100644 → 0
View file @
ff5b09fc
appname
=
chat
httpport
=
8080
runmode
=
dev
example/chat/controllers/default.go
deleted
100644 → 0
View file @
ff5b09fc
// Beego (http://beego.me/)
// @description beego is an open-source, high-performance web framework for the Go programming language.
// @link http://github.com/astaxie/beego for the canonical source repository
// @license http://github.com/astaxie/beego/blob/master/LICENSE
// @authors Unknwon
package
controllers
import
(
"github.com/astaxie/beego"
)
type
MainController
struct
{
beego
.
Controller
}
func
(
m
*
MainController
)
Get
()
{
m
.
Data
[
"host"
]
=
m
.
Ctx
.
Request
.
Host
m
.
TplNames
=
"index.tpl"
}
example/chat/controllers/ws.go
deleted
100644 → 0
View file @
ff5b09fc
// Beego (http://beego.me/)
// @description beego is an open-source, high-performance web framework for the Go programming language.
// @link http://github.com/astaxie/beego for the canonical source repository
// @license http://github.com/astaxie/beego/blob/master/LICENSE
// @authors Unknwon
package
controllers
import
(
"io/ioutil"
"math/rand"
"net/http"
"time"
"github.com/astaxie/beego"
"github.com/gorilla/websocket"
)
const
(
// Time allowed to write a message to the client.
writeWait
=
10
*
time
.
Second
// Time allowed to read the next message from the client.
readWait
=
60
*
time
.
Second
// Send pings to client with this period. Must be less than readWait.
pingPeriod
=
(
readWait
*
9
)
/
10
// Maximum message size allowed from client.
maxMessageSize
=
512
)
func
init
()
{
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
go
h
.
run
()
}
// connection is an middleman between the websocket connection and the hub.
type
connection
struct
{
username
string
// The websocket connection.
ws
*
websocket
.
Conn
// Buffered channel of outbound messages.
send
chan
[]
byte
}
// readPump pumps messages from the websocket connection to the hub.
func
(
c
*
connection
)
readPump
()
{
defer
func
()
{
h
.
unregister
<-
c
c
.
ws
.
Close
()
}()
c
.
ws
.
SetReadLimit
(
maxMessageSize
)
c
.
ws
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
readWait
))
c
.
ws
.
SetPongHandler
(
func
(
string
)
error
{
c
.
ws
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
readWait
));
return
nil
})
for
{
op
,
r
,
err
:=
c
.
ws
.
NextReader
()
if
err
!=
nil
{
break
}
switch
op
{
case
websocket
.
TextMessage
:
message
,
err
:=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
break
}
h
.
broadcast
<-
[]
byte
(
c
.
username
+
"_"
+
time
.
Now
()
.
Format
(
"15:04:05"
)
+
":"
+
string
(
message
))
}
}
}
// write writes a message with the given opCode and payload.
func
(
c
*
connection
)
write
(
opCode
int
,
payload
[]
byte
)
error
{
c
.
ws
.
SetWriteDeadline
(
time
.
Now
()
.
Add
(
writeWait
))
return
c
.
ws
.
WriteMessage
(
opCode
,
payload
)
}
// writePump pumps messages from the hub to the websocket connection.
func
(
c
*
connection
)
writePump
()
{
ticker
:=
time
.
NewTicker
(
pingPeriod
)
defer
func
()
{
ticker
.
Stop
()
c
.
ws
.
Close
()
}()
for
{
select
{
case
message
,
ok
:=
<-
c
.
send
:
if
!
ok
{
c
.
write
(
websocket
.
CloseMessage
,
[]
byte
{})
return
}
if
err
:=
c
.
write
(
websocket
.
TextMessage
,
message
);
err
!=
nil
{
return
}
case
<-
ticker
.
C
:
if
err
:=
c
.
write
(
websocket
.
PingMessage
,
[]
byte
{});
err
!=
nil
{
return
}
}
}
}
type
hub
struct
{
// Registered connections.
connections
map
[
*
connection
]
bool
// Inbound messages from the connections.
broadcast
chan
[]
byte
// Register requests from the connections.
register
chan
*
connection
// Unregister requests from connections.
unregister
chan
*
connection
}
var
h
=
&
hub
{
broadcast
:
make
(
chan
[]
byte
,
maxMessageSize
),
register
:
make
(
chan
*
connection
,
1
),
unregister
:
make
(
chan
*
connection
,
1
),
connections
:
make
(
map
[
*
connection
]
bool
),
}
func
(
h
*
hub
)
run
()
{
for
{
select
{
case
c
:=
<-
h
.
register
:
h
.
connections
[
c
]
=
true
case
c
:=
<-
h
.
unregister
:
delete
(
h
.
connections
,
c
)
close
(
c
.
send
)
case
m
:=
<-
h
.
broadcast
:
for
c
:=
range
h
.
connections
{
select
{
case
c
.
send
<-
m
:
default
:
close
(
c
.
send
)
delete
(
h
.
connections
,
c
)
}
}
}
}
}
type
WSController
struct
{
beego
.
Controller
}
var
upgrader
=
websocket
.
Upgrader
{
ReadBufferSize
:
1024
,
WriteBufferSize
:
1024
,
}
func
(
w
*
WSController
)
Get
()
{
ws
,
err
:=
upgrader
.
Upgrade
(
w
.
Ctx
.
ResponseWriter
,
w
.
Ctx
.
Request
,
nil
)
if
_
,
ok
:=
err
.
(
websocket
.
HandshakeError
);
ok
{
http
.
Error
(
w
.
Ctx
.
ResponseWriter
,
"Not a websocket handshake"
,
400
)
return
}
else
if
err
!=
nil
{
return
}
c
:=
&
connection
{
send
:
make
(
chan
[]
byte
,
256
),
ws
:
ws
,
username
:
randomString
(
10
)}
h
.
register
<-
c
go
c
.
writePump
()
c
.
readPump
()
}
func
randomString
(
l
int
)
string
{
bytes
:=
make
([]
byte
,
l
)
for
i
:=
0
;
i
<
l
;
i
++
{
bytes
[
i
]
=
byte
(
randInt
(
65
,
90
))
}
return
string
(
bytes
)
}
func
randInt
(
min
int
,
max
int
)
int
{
return
min
+
rand
.
Intn
(
max
-
min
)
}
example/chat/main.go
deleted
100644 → 0
View file @
ff5b09fc
// Beego (http://beego.me/)
// @description beego is an open-source, high-performance web framework for the Go programming language.
// @link http://github.com/astaxie/beego for the canonical source repository
// @license http://github.com/astaxie/beego/blob/master/LICENSE
// @authors Unknwon
package
main
import
(
"github.com/astaxie/beego"
"github.com/astaxie/beego/example/chat/controllers"
)
func
main
()
{
beego
.
Router
(
"/"
,
&
controllers
.
MainController
{})
beego
.
Router
(
"/ws"
,
&
controllers
.
WSController
{})
beego
.
Run
()
}
example/chat/views/index.tpl
deleted
100644 → 0
View file @
ff5b09fc
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
Chat Example
</title>
<script
src=
"//code.jquery.com/jquery-2.1.3.min.js"
></script>
<script
type=
"text/javascript"
>
$
(
function
()
{
var
conn
;
var
msg
=
$
(
"#msg"
);
var
log
=
$
(
"#log"
);
function
appendLog
(
msg
)
{
var
d
=
log
[
0
]
var
doScroll
=
d
.
scrollTop
==
d
.
scrollHeight
-
d
.
clientHeight
;
msg
.
appendTo
(
log
)
if
(
doScroll
)
{
d
.
scrollTop
=
d
.
scrollHeight
-
d
.
clientHeight
;
}
}
$
(
"#form"
).
submit
(
function
()
{
if
(
!
conn
)
{
return
false
;
}
if
(
!
msg
.
val
())
{
return
false
;
}
conn
.
send
(
msg
.
val
());
msg
.
val
(
""
);
return
false
});
if
(
window
[
"WebSocket"
])
{
conn
=
new
WebSocket
(
"ws://{{.host}}/ws"
);
conn
.
onclose
=
function
(
evt
)
{
appendLog
(
$
(
"<div><b>Connection closed.</b></div>"
))
}
conn
.
onmessage
=
function
(
evt
)
{
appendLog
(
$
(
"<div/>"
).
text
(
evt
.
data
))
}
}
else
{
appendLog
(
$
(
"<div><b>Your browser does not support WebSockets.</b></div>"
))
}
});
</script>
<style
type=
"text/css"
>
html
{
overflow
:
hidden
;
}
body
{
overflow
:
hidden
;
padding
:
0
;
margin
:
0
;
width
:
100%
;
height
:
100%
;
background
:
gray
;
}
#log
{
background
:
white
;
margin
:
0
;
padding
:
0.5em
0.5em
0.5em
0.5em
;
position
:
absolute
;
top
:
0.5em
;
left
:
0.5em
;
right
:
0.5em
;
bottom
:
3em
;
overflow
:
auto
;
}
#form
{
padding
:
0
0.5em
0
0.5em
;
margin
:
0
;
position
:
absolute
;
bottom
:
1em
;
left
:
0px
;
width
:
100%
;
overflow
:
hidden
;
}
</style>
</head>
<body>
<div
id=
"log"
></div>
<form
id=
"form"
>
<input
type=
"submit"
value=
"Send"
/>
<input
type=
"text"
id=
"msg"
size=
"64"
/>
</form>
</body>
</html>
\ No newline at end of file
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