Browse Source

add ktogame

WADE 2 years ago
commit
42e697353a
10 changed files with 154 additions and 0 deletions
  1. 3 0
      conf/app.conf
  2. 4 0
      controllers/data.go
  3. 34 0
      controllers/default.go
  4. 6 0
      go.mod
  5. 11 0
      main.go
  6. 40 0
      models/mysql.go
  7. 10 0
      routers/router.go
  8. 1 0
      static/js/reload.min.js
  9. 39 0
      tests/default_test.go
  10. 6 0
      views/index.tpl

+ 3 - 0
conf/app.conf

@@ -0,0 +1,3 @@
+appname = ktogame
+httpport = 8080
+runmode = dev

+ 4 - 0
controllers/data.go

@@ -0,0 +1,4 @@
+package controllers
+
+type Data struct {
+}

+ 34 - 0
controllers/default.go

@@ -0,0 +1,34 @@
+package controllers
+
+import (
+	"github.com/astaxie/beego"
+)
+
+type MainController struct {
+	beego.Controller
+	S *xorm.Engine
+}
+
+func (c *MainController) Get() {
+	c.Data["Website"] = "beego.me"
+	c.Data["Email"] = "astaxie@gmail.com"
+	c.TplName = "index.tpl"
+}
+
+//参与
+func (c *MainController) Send() {
+	var addr, inviter string
+	var amount int
+	//统计收益
+}
+
+//复投
+
+func (c *MainController) SendTx1() {
+
+}
+
+//领取
+func (c *MainController) GetA() {
+
+}

+ 6 - 0
go.mod

@@ -0,0 +1,6 @@
+module ktogame
+
+go 1.16
+
+require github.com/astaxie/beego v1.12.1
+require github.com/smartystreets/goconvey v1.6.4

+ 11 - 0
main.go

@@ -0,0 +1,11 @@
+package main
+
+import (
+	_ "ktogame/routers"
+	"github.com/astaxie/beego"
+)
+
+func main() {
+	beego.Run()
+}
+

+ 40 - 0
models/mysql.go

@@ -0,0 +1,40 @@
+package connect
+
+import (
+	"fmt"
+	"log"
+
+	_ "github.com/go-sql-driver/mysql"
+	"github.com/go-xorm/xorm"
+)
+
+var Engine *xorm.Engine
+
+func init() {
+	var err error
+
+	// ip := beego.AppConfig.String("sqlIp")
+	// port := beego.AppConfig.String("sqlPort")
+	// user := beego.AppConfig.String("sqlUser")
+	// pwd := beego.AppConfig.String("sqlPwd")
+	// dbname := beego.AppConfig.String("sqlName")
+	// fmt.Println("ip", ip)
+	// Engine, err = xorm.NewEngine("mysql", user+":"+pwd+"@tcp("+ip+":+"+port+")/"+dbname+"?charset=utf8")
+
+	/* 	118.193.32.118
+	game,1K91NDp%Y */
+
+	Engine, err = xorm.NewEngine("mysql", "game:1K91NDp%Y@tcp(118.193.32.118:3306)/game?charset=utf8")
+	err = Engine.Ping()
+
+	if err != nil {
+		log.Fatal(err)
+	}
+	fmt.Println("==========Conn  Sqldb  SUCC==========")
+
+}
+
+//创建事务
+func NewSession() *xorm.Session {
+	return Engine.NewSession()
+}

+ 10 - 0
routers/router.go

@@ -0,0 +1,10 @@
+package routers
+
+import (
+	"ktogame/controllers"
+	"github.com/astaxie/beego"
+)
+
+func init() {
+    beego.Router("/", &controllers.MainController{})
+}

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

@@ -0,0 +1,39 @@
+package test
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"testing"
+	"runtime"
+	"path/filepath"
+	_ "ktogame/routers"
+
+	"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)
+	        })
+	})
+}
+

File diff suppressed because it is too large
+ 6 - 0
views/index.tpl


Some files were not shown because too many files changed in this diff