zhengchengwu hace 5 años
commit
3ba4054b06
Se han modificado 7 ficheros con 174 adiciones y 0 borrados
  1. 3 0
      conf/app.conf
  2. 15 0
      controllers/default.go
  3. 11 0
      main.go
  4. 10 0
      routers/router.go
  5. 1 0
      static/js/reload.min.js
  6. 39 0
      tests/default_test.go
  7. 95 0
      views/index.tpl

+ 3 - 0
conf/app.conf Ver fichero

@@ -0,0 +1,3 @@
1
+appname = wsc-go
2
+httpport = 8080
3
+runmode = dev

+ 15 - 0
controllers/default.go Ver fichero

@@ -0,0 +1,15 @@
1
+package controllers
2
+
3
+import (
4
+	"github.com/astaxie/beego"
5
+)
6
+
7
+type MainController struct {
8
+	beego.Controller
9
+}
10
+
11
+func (c *MainController) Get() {
12
+	c.Data["Website"] = "beego.me"
13
+	c.Data["Email"] = "astaxie@gmail.com"
14
+	c.TplName = "index.tpl"
15
+}

+ 11 - 0
main.go Ver fichero

@@ -0,0 +1,11 @@
1
+package main
2
+
3
+import (
4
+	_ "wsc-go/routers"
5
+	"github.com/astaxie/beego"
6
+)
7
+
8
+func main() {
9
+	beego.Run()
10
+}
11
+

+ 10 - 0
routers/router.go Ver fichero

@@ -0,0 +1,10 @@
1
+package routers
2
+
3
+import (
4
+	"wsc-go/controllers"
5
+	"github.com/astaxie/beego"
6
+)
7
+
8
+func init() {
9
+    beego.Router("/", &controllers.MainController{})
10
+}

+ 1 - 0
static/js/reload.min.js Ver fichero

@@ -0,0 +1 @@
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 - 0
tests/default_test.go Ver fichero

@@ -0,0 +1,39 @@
1
+package test
2
+
3
+import (
4
+	"net/http"
5
+	"net/http/httptest"
6
+	"testing"
7
+	"runtime"
8
+	"path/filepath"
9
+	_ "wsc-go/routers"
10
+
11
+	"github.com/astaxie/beego"
12
+	. "github.com/smartystreets/goconvey/convey"
13
+)
14
+
15
+func init() {
16
+	_, file, _, _ := runtime.Caller(0)
17
+	apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
18
+	beego.TestBeegoInit(apppath)
19
+}
20
+
21
+
22
+// TestBeego is a sample to run an endpoint test
23
+func TestBeego(t *testing.T) {
24
+	r, _ := http.NewRequest("GET", "/", nil)
25
+	w := httptest.NewRecorder()
26
+	beego.BeeApp.Handlers.ServeHTTP(w, r)
27
+
28
+	beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())
29
+
30
+	Convey("Subject: Test Station Endpoint\n", t, func() {
31
+	        Convey("Status Code Should Be 200", func() {
32
+	                So(w.Code, ShouldEqual, 200)
33
+	        })
34
+	        Convey("The Result Should Not Be Empty", func() {
35
+	                So(w.Body.Len(), ShouldBeGreaterThan, 0)
36
+	        })
37
+	})
38
+}
39
+

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 95 - 0
views/index.tpl