From 0d86fb58bb29b2ea0b002ee9952797017f04685e Mon Sep 17 00:00:00 2001 From: VIVIMAN Date: Sun, 4 Dec 2022 14:24:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + conf/app.conf | 3 ++ controllers/default.go | 15 +++++++ go.mod | 10 +++++ main.go | 10 +++++ routers/router.go | 10 +++++ static/js/reload.min.js | 1 + tests/default_test.go | 37 ++++++++++++++++ views/index.tpl | 97 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 184 insertions(+) create mode 100644 .gitignore create mode 100644 conf/app.conf create mode 100644 controllers/default.go create mode 100644 go.mod create mode 100644 main.go create mode 100644 routers/router.go create mode 100644 static/js/reload.min.js create mode 100644 tests/default_test.go create mode 100644 views/index.tpl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4170155 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/go.sum diff --git a/conf/app.conf b/conf/app.conf new file mode 100644 index 0000000..8175ee4 --- /dev/null +++ b/conf/app.conf @@ -0,0 +1,3 @@ +appname = bee_learn +httpport = 8080 +runmode = dev diff --git a/controllers/default.go b/controllers/default.go new file mode 100644 index 0000000..e2abba3 --- /dev/null +++ b/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"] = "官网.地址" + c.Data["Email"] = "张献维@邮箱.com" + c.TplName = "index.tpl" +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..96e74e1 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module bee_learn + +go 1.14 + +require github.com/astaxie/beego v1.12.1 + +require ( + github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect + github.com/smartystreets/goconvey v1.6.4 +) diff --git a/main.go b/main.go new file mode 100644 index 0000000..6f8ed54 --- /dev/null +++ b/main.go @@ -0,0 +1,10 @@ +package main + +import ( + _ "bee_learn/routers" + "github.com/astaxie/beego" +) + +func main() { + beego.Run() +} diff --git a/routers/router.go b/routers/router.go new file mode 100644 index 0000000..0b9161c --- /dev/null +++ b/routers/router.go @@ -0,0 +1,10 @@ +package routers + +import ( + "bee_learn/controllers" + "github.com/astaxie/beego" +) + +func init() { + beego.Router("/", &controllers.MainController{}) +} 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..0dad966 --- /dev/null +++ b/tests/default_test.go @@ -0,0 +1,37 @@ +package test + +import ( + _ "bee_learn/routers" + "net/http" + "net/http/httptest" + "path/filepath" + "runtime" + "testing" + + "github.com/astaxie/beego" + . "github.com/smartystreets/goconvey/convey" +) + +func init() { + _, file, _, _ := runtime.Caller(0) + 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/index.tpl b/views/index.tpl new file mode 100644 index 0000000..73f4147 --- /dev/null +++ b/views/index.tpl @@ -0,0 +1,97 @@ + + + + + Beego + + + + + + + +
+

欢迎学习

+
+ 这是一个简单样例 +
+
+ +
+ + + +