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
2121c4dd
authored
2012-03-30 23:48:36 +0800
by
xiemengjun
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
modify struc
1 parent
446daaea
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
88 deletions
beego/beego.go
examples/blog/blog.go
examples/blog/configs/app.yaml
examples/blog/controller/user.go
examples/blog/model/user.go
beego/beego.go
View file @
2121c4d
package
beego
import
"./core"
import
{
"net"
"net/http"
"net/http/fcgi"
"log"
"strconv"
"./core"
}
type
C
struct
{
core
.
Content
}
...
...
@@ -25,3 +31,28 @@ type A struct{
type
V
struct
{
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 @
2121c4d
...
...
@@ -5,92 +5,14 @@
package
guestbook
import
(
"io"
"net/http"
"text/template"
"time"
"appengine"
"appengine/datastore"
"appengine/user"
"../../beego"
)
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
()
{
beego
.
C
.
loadconfig
()
}
func
init
()
{
http
.
HandleFunc
(
"/"
,
handleMainPage
)
http
.
HandleFunc
(
"/sign"
,
handleSign
)
func
main
()
{
app
:=
beego
.
App
app
.
Run
(
)
}
\ No newline at end of file
...
...
examples/blog/configs/app.yaml
View file @
2121c4d
application
:
guestbook-go
application
:
blog
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 @
2121c4d
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 @
2121c4d
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
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