From 47cf1d244ba6cdf20d50c51dedc054b23abd0169 Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Tue, 31 Jul 2018 09:56:34 +0800 Subject: init msb2pilot project init project by beego Issue-ID: MSB-230 Change-Id: Iaf3afb1f8d28e54d61c0bd401737d2604149ff0b Signed-off-by: Lvbo163 --- msb2pilot/src/msb2pilot/conf/app.conf | 3 + msb2pilot/src/msb2pilot/controllers/default.go | 26 ++++++ msb2pilot/src/msb2pilot/main.go | 22 +++++ msb2pilot/src/msb2pilot/routers/router.go | 22 +++++ msb2pilot/src/msb2pilot/static/js/reload.min.js | 12 +++ msb2pilot/src/msb2pilot/tests/default_test.go | 48 +++++++++++ msb2pilot/src/msb2pilot/views/index.tpl | 108 ++++++++++++++++++++++++ 7 files changed, 241 insertions(+) create mode 100644 msb2pilot/src/msb2pilot/conf/app.conf create mode 100644 msb2pilot/src/msb2pilot/controllers/default.go create mode 100644 msb2pilot/src/msb2pilot/main.go create mode 100644 msb2pilot/src/msb2pilot/routers/router.go create mode 100644 msb2pilot/src/msb2pilot/static/js/reload.min.js create mode 100644 msb2pilot/src/msb2pilot/tests/default_test.go create mode 100644 msb2pilot/src/msb2pilot/views/index.tpl (limited to 'msb2pilot') diff --git a/msb2pilot/src/msb2pilot/conf/app.conf b/msb2pilot/src/msb2pilot/conf/app.conf new file mode 100644 index 0000000..2b61535 --- /dev/null +++ b/msb2pilot/src/msb2pilot/conf/app.conf @@ -0,0 +1,3 @@ +appname = msb2pilot +httpport = 8080 +runmode = dev diff --git a/msb2pilot/src/msb2pilot/controllers/default.go b/msb2pilot/src/msb2pilot/controllers/default.go new file mode 100644 index 0000000..63e8ad0 --- /dev/null +++ b/msb2pilot/src/msb2pilot/controllers/default.go @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2018 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial Project + */ +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/msb2pilot/src/msb2pilot/main.go b/msb2pilot/src/msb2pilot/main.go new file mode 100644 index 0000000..84e9b24 --- /dev/null +++ b/msb2pilot/src/msb2pilot/main.go @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2018 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial Project + */ +package main + +import ( + _ "msb2pilot/routers" + + "github.com/astaxie/beego" +) + +func main() { + beego.Run() +} diff --git a/msb2pilot/src/msb2pilot/routers/router.go b/msb2pilot/src/msb2pilot/routers/router.go new file mode 100644 index 0000000..1a8d1e5 --- /dev/null +++ b/msb2pilot/src/msb2pilot/routers/router.go @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2018 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial Project + */ +package routers + +import ( + "msb2pilot/controllers" + + "github.com/astaxie/beego" +) + +func init() { + beego.Router("/", &controllers.MainController{}) +} diff --git a/msb2pilot/src/msb2pilot/static/js/reload.min.js b/msb2pilot/src/msb2pilot/static/js/reload.min.js new file mode 100644 index 0000000..0c4d40d --- /dev/null +++ b/msb2pilot/src/msb2pilot/static/js/reload.min.js @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2018 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial Project + */ +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/msb2pilot/src/msb2pilot/tests/default_test.go b/msb2pilot/src/msb2pilot/tests/default_test.go new file mode 100644 index 0000000..2741d10 --- /dev/null +++ b/msb2pilot/src/msb2pilot/tests/default_test.go @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2018 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial Project + */ +package test + +import ( + _ "msb2pilot/routers" + "net/http" + "net/http/httptest" + "path/filepath" + "runtime" + "testing" + + "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/msb2pilot/src/msb2pilot/views/index.tpl b/msb2pilot/src/msb2pilot/views/index.tpl new file mode 100644 index 0000000..5ee08ef --- /dev/null +++ b/msb2pilot/src/msb2pilot/views/index.tpl @@ -0,0 +1,108 @@ + + + + + + Beego + + + + + + + +
+

Welcome to Beego

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