yirenyishi
6 年之前
當前提交
853086d707
共有 13 個文件被更改,包括 171 次插入 和 0 次删除
@ -0,0 +1,3 @@ |
|||
appname = beeblog |
|||
httpport = 8082 |
|||
runmode = dev |
@ -0,0 +1,13 @@ |
|||
package controllers |
|||
|
|||
import ( |
|||
"github.com/astaxie/beego" |
|||
) |
|||
|
|||
type IndexController struct { |
|||
beego.Controller |
|||
} |
|||
|
|||
func (c *IndexController) Get() { |
|||
c.TplName = "index.html" |
|||
} |
@ -0,0 +1,15 @@ |
|||
package controllers |
|||
|
|||
import "github.com/astaxie/beego" |
|||
|
|||
type UserController struct { |
|||
beego.Controller |
|||
} |
|||
|
|||
func (u *UserController) LoginPage() { |
|||
u.Ctx.WriteString("login page") |
|||
} |
|||
|
|||
func (u *UserController) Login() { |
|||
u.Ctx.WriteString("login method") |
|||
} |
Binary file not shown.
@ -0,0 +1,18 @@ |
|||
package main |
|||
|
|||
import ( |
|||
_ "beeblog/routers" |
|||
"github.com/astaxie/beego" |
|||
"beeblog/models" |
|||
"github.com/astaxie/beego/orm" |
|||
) |
|||
|
|||
func init() { |
|||
models.RegistDB() |
|||
} |
|||
func main() { |
|||
orm.Debug = true |
|||
orm.RunSyncdb("default",false,true) |
|||
beego.Run() |
|||
} |
|||
|
@ -0,0 +1,24 @@ |
|||
package models |
|||
|
|||
import ( |
|||
"github.com/Unknwon/com" |
|||
"os" |
|||
"path" |
|||
"github.com/astaxie/beego/orm" |
|||
_ "github.com/mattn/go-sqlite3" |
|||
) |
|||
|
|||
const( |
|||
_DB_NAME = "data/beeblog.db" |
|||
_SQLITE3_DRIVER = "sqlite3" |
|||
) |
|||
|
|||
func RegistDB() { |
|||
if !com.IsExist(_DB_NAME){ |
|||
os.MkdirAll(path.Dir(_DB_NAME),os.ModePerm) |
|||
os.Create(_DB_NAME) |
|||
} |
|||
orm.RegisterModel(new(Category),new(Topic)) |
|||
orm.RegisterDriver(_SQLITE3_DRIVER,orm.DRSqlite) |
|||
orm.RegisterDataBase("default",_SQLITE3_DRIVER,_DB_NAME,10) |
|||
} |
@ -0,0 +1,8 @@ |
|||
package models |
|||
|
|||
type Category struct { |
|||
Id int64 |
|||
Title string |
|||
Views int64 `orm:"index"` |
|||
TopicCount int64 |
|||
} |
@ -0,0 +1,15 @@ |
|||
package models |
|||
|
|||
import "time" |
|||
|
|||
type Topic struct { |
|||
Id int64 |
|||
Uid int64 |
|||
Title string |
|||
Content string `orm:"size(5000)"` |
|||
Attachment string |
|||
Created time.Time `orm:"index"` |
|||
ViewCount int64 `orm:"index"` |
|||
Author string |
|||
ReplayCount int64 |
|||
} |
@ -0,0 +1,13 @@ |
|||
package routers |
|||
|
|||
import ( |
|||
"beeblog/controllers" |
|||
"github.com/astaxie/beego" |
|||
) |
|||
|
|||
func init() { |
|||
beego.Router("/", &controllers.IndexController{}) |
|||
beego.Router("/login", &controllers.UserController{}, "Get:LoginPage") |
|||
beego.Router("/login", &controllers.UserController{}, "post:Login") |
|||
|
|||
} |
@ -0,0 +1 @@ |
|||
function b(a){var c=new WebSocket(a);c.onclose=function(){setTimeout(function(){b(a)},2E3)};c.onmessage=function(){location.reload()}}try{if(window.WebSocket)try{b("ws://localhost:12450/reload")}catch(a){console.error(a)}else console.log("Your browser does not support WebSockets.")}catch(a){console.error("Exception during connecting to Reload:",a)}; |
@ -0,0 +1,39 @@ |
|||
package test |
|||
|
|||
import ( |
|||
"net/http" |
|||
"net/http/httptest" |
|||
"testing" |
|||
"runtime" |
|||
"path/filepath" |
|||
_ "beeblog/routers" |
|||
|
|||
"github.com/astaxie/beego" |
|||
. "github.com/smartystreets/goconvey/convey" |
|||
) |
|||
|
|||
func init() { |
|||
_, file, _, _ := runtime.Caller(1) |
|||
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator)))) |
|||
beego.TestBeegoInit(apppath) |
|||
} |
|||
|
|||
|
|||
// TestBeego is a sample to run an endpoint test
|
|||
func TestBeego(t *testing.T) { |
|||
r, _ := http.NewRequest("GET", "/", nil) |
|||
w := httptest.NewRecorder() |
|||
beego.BeeApp.Handlers.ServeHTTP(w, r) |
|||
|
|||
beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String()) |
|||
|
|||
Convey("Subject: Test Station Endpoint\n", t, func() { |
|||
Convey("Status Code Should Be 200", func() { |
|||
So(w.Code, ShouldEqual, 200) |
|||
}) |
|||
Convey("The Result Should Not Be Empty", func() { |
|||
So(w.Body.Len(), ShouldBeGreaterThan, 0) |
|||
}) |
|||
}) |
|||
} |
|||
|
@ -0,0 +1,8 @@ |
|||
{{define "header"}} |
|||
<!DOCTYPE html> |
|||
<html> |
|||
<head> |
|||
<title>Beego</title> |
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|||
<link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> |
|||
{{end}} |
@ -0,0 +1,14 @@ |
|||
{{template "header"}} |
|||
</head> |
|||
<body> |
|||
<div> |
|||
<ul class="nav nav-pills"> |
|||
<li role="presentation" class="active"><a href="/">首页</a></li> |
|||
<li role="presentation"><a href="/">列表</a></li> |
|||
<li role="presentation"><a href="/">分类</a></li> |
|||
</ul> |
|||
</div> |
|||
<script src="/static/js/reload.min.js"></script> |
|||
</body> |
|||
<script src="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script> |
|||
</html> |
Loading…
Reference in new issue