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
2121c4dd
Commit
2121c4dd
authored
Mar 30, 2012
by
xiemengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify struc
parent
446daaea
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
89 deletions
+75
-89
beego.go
beego/beego.go
+34
-2
blog.go
examples/blog/blog.go
+8
-85
app.yaml
examples/blog/configs/app.yaml
+6
-2
user.go
examples/blog/controller/user.go
+12
-0
user.go
examples/blog/model/user.go
+15
-0
No files found.
beego/beego.go
View file @
2121c4dd
package
beego
package
beego
import
"./core"
import
{
"net"
"net/http"
"net/http/fcgi"
"log"
"strconv"
"./core"
}
type
C
struct
{
type
C
struct
{
core
.
Content
core
.
Content
}
}
...
@@ -24,4 +30,29 @@ type A struct{
...
@@ -24,4 +30,29 @@ type A struct{
type
V
struct
{
type
V
struct
{
core
.
View
core
.
View
}
type
BeegoApp
struct
{
Port
int
}
func
(
app
*
BeegoApp
)
BeeListen
(
port
int
)
{
app
.
Port
=
port
err
:=
http
.
ListenAndServe
(
":"
+
strconv
.
Itoa
(
app
.
Port
),
nil
)
if
err
!=
nil
{
log
.
Fatal
(
"ListenAndServe: "
,
err
)
}
}
func
(
app
*
BeegoApp
)
BeeListenFcgi
(
port
int
)
{
app
.
Port
=
port
l
,
err
:=
net
.
Listen
(
"tcp"
,
"127.0.0.1:"
+
strconv
.
Itoa
(
port
))
if
err
!=
nil
{
log
.
Fatal
(
"ListenAndServe: "
,
err
)
}
fcgi
.
Serve
(
l
,
app
.
Handler
)
}
func
Run
()
{
rootPath
,
_
:=
os
.
Getwd
()
}
}
\ No newline at end of file
examples/blog/blog.go
View file @
2121c4dd
...
@@ -5,92 +5,14 @@
...
@@ -5,92 +5,14 @@
package
guestbook
package
guestbook
import
(
import
(
"io"
"../../beego"
"net/http"
"text/template"
"time"
"appengine"
"appengine/datastore"
"appengine/user"
)
)
type
Greeting
struct
{
Author
string
Content
string
Date
time
.
Time
}
func
serve404
(
w
http
.
ResponseWriter
)
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain; charset=utf-8"
)
io
.
WriteString
(
w
,
"Not Found"
)
}
func
serveError
(
c
appengine
.
Context
,
w
http
.
ResponseWriter
,
err
error
)
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain; charset=utf-8"
)
io
.
WriteString
(
w
,
"Internal Server Error"
)
c
.
Errorf
(
"%v"
,
err
)
}
var
mainPage
=
template
.
Must
(
template
.
New
(
"guestbook"
)
.
Parse
(
`<html><body>
{{range .}}
{{with .Author}}<b>{{.|html}}</b>{{else}}An anonymous person{{end}}
on <em>{{.Date.Format "3:04pm, Mon 2 Jan"}}</em>
wrote <blockquote>{{.Content|html}}</blockquote>
{{end}}
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form></body></html>
`
))
func
handleMainPage
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
!=
"GET"
||
r
.
URL
.
Path
!=
"/"
{
serve404
(
w
)
return
}
c
:=
appengine
.
NewContext
(
r
)
q
:=
datastore
.
NewQuery
(
"Greeting"
)
.
Order
(
"-Date"
)
.
Limit
(
10
)
var
gg
[]
*
Greeting
_
,
err
:=
q
.
GetAll
(
c
,
&
gg
)
if
err
!=
nil
{
serveError
(
c
,
w
,
err
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
if
err
:=
mainPage
.
Execute
(
w
,
gg
);
err
!=
nil
{
c
.
Errorf
(
"%v"
,
err
)
}
}
func
handleSign
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
!=
"POST"
{
serve404
(
w
)
return
}
c
:=
appengine
.
NewContext
(
r
)
if
err
:=
r
.
ParseForm
();
err
!=
nil
{
serveError
(
c
,
w
,
err
)
return
}
g
:=
&
Greeting
{
Content
:
r
.
FormValue
(
"content"
),
Date
:
time
.
Now
(),
}
if
u
:=
user
.
Current
(
c
);
u
!=
nil
{
g
.
Author
=
u
.
String
()
}
if
_
,
err
:=
datastore
.
Put
(
c
,
datastore
.
NewIncompleteKey
(
c
,
"Greeting"
,
nil
),
g
);
err
!=
nil
{
serveError
(
c
,
w
,
err
)
return
}
http
.
Redirect
(
w
,
r
,
"/"
,
http
.
StatusFound
)
}
func
init
()
{
func
init
()
{
http
.
HandleFunc
(
"/"
,
handleMainPage
)
beego
.
C
.
loadconfig
()
http
.
HandleFunc
(
"/sign"
,
handleSign
)
}
}
func
main
()
{
app
:=
beego
.
App
app
.
Run
()
}
\ No newline at end of file
examples/blog/configs/app.yaml
View file @
2121c4dd
application
:
guestbook-go
application
:
blog
handlers
:
handlers
:
-
url
:
/.*
-
url
:
"
/user"
handlefun:"user.Index"
-
url
:
"
/blog"
handlefun:"blog.Index"
\ No newline at end of file
examples/blog/controller/user.go
0 → 100644
View file @
2121c4dd
package
controller
import
(
"github.com/astaxie/beego/beego"
"../model"
)
func
UserIndex
(
w
beego
.
A
)
{
userinfo
:=
model
.
User
.
getAll
()
beego
.
V
.
Render
(
w
,
"users/index"
)
}
\ No newline at end of file
examples/blog/model/user.go
0 → 100644
View file @
2121c4dd
package
model
import
(
"./beego"
)
type
Users
struct
{
username
string
password
string
beego
.
M
}
func
NewUsers
()
(
a
*
Users
)
{
return
&
Users
{}
}
\ 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