commit 853086d7072ddaeed8b91906222e22b9c4f274fe Author: yirenyishi Date: Mon Nov 12 23:33:28 2018 +0800 init diff --git a/conf/app.conf b/conf/app.conf new file mode 100644 index 0000000..83d998b --- /dev/null +++ b/conf/app.conf @@ -0,0 +1,3 @@ +appname = beeblog +httpport = 8082 +runmode = dev diff --git a/controllers/IndexController.go b/controllers/IndexController.go new file mode 100644 index 0000000..c9dac5b --- /dev/null +++ b/controllers/IndexController.go @@ -0,0 +1,13 @@ +package controllers + +import ( + "github.com/astaxie/beego" +) + +type IndexController struct { + beego.Controller +} + +func (c *IndexController) Get() { + c.TplName = "index.html" +} diff --git a/controllers/UserController.go b/controllers/UserController.go new file mode 100644 index 0000000..c4593e2 --- /dev/null +++ b/controllers/UserController.go @@ -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") +} \ No newline at end of file diff --git a/data/beeblog.db b/data/beeblog.db new file mode 100644 index 0000000..eeb54b4 Binary files /dev/null and b/data/beeblog.db differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..0b78bdf --- /dev/null +++ b/main.go @@ -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() +} + diff --git a/models/datainit.go b/models/datainit.go new file mode 100644 index 0000000..021a5f5 --- /dev/null +++ b/models/datainit.go @@ -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) +} \ No newline at end of file diff --git a/models/struct.go b/models/struct.go new file mode 100644 index 0000000..33b655c --- /dev/null +++ b/models/struct.go @@ -0,0 +1,8 @@ +package models + +type Category struct { + Id int64 + Title string + Views int64 `orm:"index"` + TopicCount int64 +} diff --git a/models/topic.go b/models/topic.go new file mode 100644 index 0000000..c771076 --- /dev/null +++ b/models/topic.go @@ -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 +} \ No newline at end of file diff --git a/routers/router.go b/routers/router.go new file mode 100644 index 0000000..bd6d6d0 --- /dev/null +++ b/routers/router.go @@ -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") + +} diff --git a/static/js/reload.min.js b/static/js/reload.min.js new file mode 100644 index 0000000..e780033 --- /dev/null +++ b/static/js/reload.min.js @@ -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)}; diff --git a/tests/default_test.go b/tests/default_test.go new file mode 100644 index 0000000..a036aa1 --- /dev/null +++ b/tests/default_test.go @@ -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) + }) + }) +} + diff --git a/views/T.header.tpl b/views/T.header.tpl new file mode 100644 index 0000000..f5b987e --- /dev/null +++ b/views/T.header.tpl @@ -0,0 +1,8 @@ +{{define "header"}} + + + + Beego + + + {{end}} \ No newline at end of file diff --git a/views/index.html b/views/index.html new file mode 100644 index 0000000..54e4429 --- /dev/null +++ b/views/index.html @@ -0,0 +1,14 @@ +{{template "header"}} + + +
+ +
+ + + +