Browse Source

add main.go

rdluck 4 years ago
parent
commit
1332b08753
4 changed files with 90 additions and 0 deletions
  1. 8 0
      .gitignore
  2. 1 0
      lastupdate.tmp
  3. 57 0
      main.go
  4. 24 0
      routers/router.go

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+/routers/commentsRouter_controllers.go
+/*.exe
+/go.sum
+/go.mod
+/rdlucklog
+/binlog
+/.idea
+/conf

+ 1 - 0
lastupdate.tmp

@@ -0,0 +1 @@
+{"E:\\code\\go\\src\\hongze\\hongze_cygx\\controllers":1611814712717539900}

+ 57 - 0
main.go

@@ -0,0 +1,57 @@
+package main
+
+import (
+	"fmt"
+	"github.com/astaxie/beego/logs"
+	_ "hongze/hongze_cygx/routers"
+	"hongze/hongze_cygx/services"
+	"hongze/hongze_cygx/utils"
+	"runtime"
+	"time"
+
+	"github.com/astaxie/beego/context"
+	"github.com/astaxie/beego"
+)
+
+func main() {
+	if beego.BConfig.RunMode == "dev" {
+		beego.BConfig.WebConfig.DirectoryIndex = true
+		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
+	}
+	go services.Task()
+
+	beego.BConfig.RecoverFunc = Recover
+	beego.Run()
+}
+
+
+func Recover(ctx *context.Context) {
+	if err := recover(); err != nil {
+		if err == beego.ErrAbort {
+			return
+		}
+		if !beego.BConfig.RecoverPanic {
+			panic(err)
+		}
+		stack := ""
+		msg := fmt.Sprintf("The request url is  %v", ctx.Input.URL())
+		stack += msg + "</br>"
+		logs.Critical(msg)
+		msg = fmt.Sprintf("The request data is %v", string(ctx.Input.RequestBody))
+		stack += msg + "</br>"
+		logs.Critical(msg)
+		msg = fmt.Sprintf("Handler crashed with error %v", err)
+		stack += msg + "</br>"
+		logs.Critical(msg)
+		for i := 1; ; i++ {
+			_, file, line, ok := runtime.Caller(i)
+			if !ok {
+				break
+			}
+			logs.Critical(fmt.Sprintf("%s:%d", file, line))
+			stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d</br>", file, line))
+		}
+		go utils.SendEmail(utils.APPNAME+"崩了"+time.Now().Format("2006-01-02 15:04:05"), stack, utils.EmailSendToUsers)
+	}
+	return
+}

+ 24 - 0
routers/router.go

@@ -0,0 +1,24 @@
+// @APIVersion 1.0.0
+// @Title beego Test API
+// @Description beego has a very cool tools to autogenerate documents for your API
+// @Contact astaxie@gmail.com
+// @TermsOfServiceUrl http://beego.me/
+// @License Apache 2.0
+// @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
+package routers
+
+import (
+	"github.com/astaxie/beego"
+	"hongze/hongze_cygx/controllers"
+)
+
+func init() {
+	ns := beego.NewNamespace("/api",
+		beego.NSNamespace("/home",
+			beego.NSInclude(
+				&controllers.HomeController{},
+			),
+		),
+	)
+	beego.AddNamespace(ns)
+}