From f5da888617ad7b436b8019cf649d759f99e07d35 Mon Sep 17 00:00:00 2001 From: HuabingZhao Date: Sat, 14 Jul 2018 13:44:06 +0800 Subject: Initial commit for msb2pilot Issue-ID: MSB-203 Change-Id: Id4ffc065d5622753c4e4839dade0add711ab004b Signed-off-by: HuabingZhao --- msb2pilot2/conf/app.conf | 3 ++ msb2pilot2/controllers/default.go | 15 ++++++ msb2pilot2/main.go | 11 +++++ msb2pilot2/routers/router.go | 10 ++++ msb2pilot2/static/js/reload.min.js | 1 + msb2pilot2/tests/default_test.go | 39 ++++++++++++++++ msb2pilot2/views/index.tpl | 95 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 174 insertions(+) create mode 100644 msb2pilot2/conf/app.conf create mode 100644 msb2pilot2/controllers/default.go create mode 100644 msb2pilot2/main.go create mode 100644 msb2pilot2/routers/router.go create mode 100644 msb2pilot2/static/js/reload.min.js create mode 100644 msb2pilot2/tests/default_test.go create mode 100644 msb2pilot2/views/index.tpl diff --git a/msb2pilot2/conf/app.conf b/msb2pilot2/conf/app.conf new file mode 100644 index 0000000..e65b269 --- /dev/null +++ b/msb2pilot2/conf/app.conf @@ -0,0 +1,3 @@ +appname = msb2pilot2 +httpport = 8080 +runmode = dev diff --git a/msb2pilot2/controllers/default.go b/msb2pilot2/controllers/default.go new file mode 100644 index 0000000..9a9e6f2 --- /dev/null +++ b/msb2pilot2/controllers/default.go @@ -0,0 +1,15 @@ +package controllers + +import ( + "github.com/astaxie/beego" +) + +type MainController struct { + beego.Controller +} + +func (c *MainController) Get() { + c.Data["Website"] = "beego.me" + c.Data["Email"] = "astaxie@gmail.com" + c.TplName = "index.tpl" +} diff --git a/msb2pilot2/main.go b/msb2pilot2/main.go new file mode 100644 index 0000000..7624e46 --- /dev/null +++ b/msb2pilot2/main.go @@ -0,0 +1,11 @@ +package main + +import ( + _ "msb2pilot2/routers" + "github.com/astaxie/beego" +) + +func main() { + beego.Run() +} + diff --git a/msb2pilot2/routers/router.go b/msb2pilot2/routers/router.go new file mode 100644 index 0000000..952ced3 --- /dev/null +++ b/msb2pilot2/routers/router.go @@ -0,0 +1,10 @@ +package routers + +import ( + "msb2pilot2/controllers" + "github.com/astaxie/beego" +) + +func init() { + beego.Router("/", &controllers.MainController{}) +} diff --git a/msb2pilot2/static/js/reload.min.js b/msb2pilot2/static/js/reload.min.js new file mode 100644 index 0000000..e780033 --- /dev/null +++ b/msb2pilot2/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/msb2pilot2/tests/default_test.go b/msb2pilot2/tests/default_test.go new file mode 100644 index 0000000..af2faa9 --- /dev/null +++ b/msb2pilot2/tests/default_test.go @@ -0,0 +1,39 @@ +package test + +import ( + "net/http" + "net/http/httptest" + "testing" + "runtime" + "path/filepath" + _ "msb2pilot2/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/msb2pilot2/views/index.tpl b/msb2pilot2/views/index.tpl new file mode 100644 index 0000000..8d6fbec --- /dev/null +++ b/msb2pilot2/views/index.tpl @@ -0,0 +1,95 @@ + + + + + Beego + + + + + + + +
+

Welcome to Beego

+
+ Beego is a simple & powerful Go web framework which is inspired by tornado and sinatra. +
+
+ +
+ + + + -- cgit 1.2.3-korg