yirenyishi pirms 6 gadiem
revīzija
853086d707
  1. 3
      conf/app.conf
  2. 13
      controllers/IndexController.go
  3. 15
      controllers/UserController.go
  4. Binārs
      data/beeblog.db
  5. 18
      main.go
  6. 24
      models/datainit.go
  7. 8
      models/struct.go
  8. 15
      models/topic.go
  9. 13
      routers/router.go
  10. 1
      static/js/reload.min.js
  11. 39
      tests/default_test.go
  12. 8
      views/T.header.tpl
  13. 14
      views/index.html

3
conf/app.conf

@ -0,0 +1,3 @@
appname = beeblog
httpport = 8082
runmode = dev

13
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"
}

15
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")
}

Binārs
data/beeblog.db

Bināro failu nav iespējams attēlot.

18
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()
}

24
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)
}

8
models/struct.go

@ -0,0 +1,8 @@
package models
type Category struct {
Id int64
Title string
Views int64 `orm:"index"`
TopicCount int64
}

15
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
}

13
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")
}

1
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)};

39
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)
})
})
}

8
views/T.header.tpl

@ -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}}

14
views/index.html

@ -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>
Notiek ielāde…
Atcelt
Saglabāt