zhangwei 3 роки тому
батько
коміт
ef4a7dca18

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+/.vscode
+/.idea

+ 8 - 13
chface/ChFaceMain.go

@@ -1,10 +1,11 @@
 package main
 
 import (
-	"chathub/chface/http"
+	"chathub/chface/core"
 	"fmt"
+	"time"
+
 	"github.com/etlibgo/et"
-	"github.com/gin-gonic/gin"
 )
 
 func main() {
@@ -12,18 +13,12 @@ func main() {
 
 	fmt.Println(et.StrPadLeft("et pad left", "0", 20))
 
-	eg := gin.Default()
-
-	http.ChHttpEntry(eg)
-
-	eg.GET("/ping", func(c *gin.Context) { // /ping是路由
-		//输出json结果给调用方
-		c.JSON(200, gin.H{
-			"message": "pong",
-		})
-	})
+	core.AppPrepare()
+	core.AppStart()
 
-	eg.Run(":8081") // 可以从本地的127.0.0.1:8081访问,不填的话,默认是8080端口
+	for core.AppIsRunning() {
+		time.Sleep(time.Duration(100) * time.Millisecond)
+	}
 
 	fmt.Println("chathub ended")
 }

+ 40 - 0
chface/core/App.go

@@ -1,13 +1,53 @@
 package core
 
+import (
+	"chathub/chface/http"
+	"fmt"
+
+	"github.com/gin-gonic/gin"
+)
+
+var sApp = struct {
+	Running bool
+}{
+	Running: false,
+}
+
 func AppPrepare() {
 
 }
 
 func AppStart() {
 
+	if sApp.Running {
+		return
+	}
+
+	sApp.Running = true
+
+	eg := gin.Default()
+
+	http.FaceHttpEntry(eg)
+
+	eg.GET("/ping", func(c *gin.Context) { // /ping是路由
+		//输出json结果给调用方
+		c.JSON(200, gin.H{
+			"message": "pong",
+		})
+	})
+
+	go eg.Run(":8082") // 可以从本地的127.0.0.1:8081访问,不填的话,默认是8080端口
+
+	fmt.Println("face AppStart started")
 }
 
 func AppStop() {
+	if !sApp.Running {
+		return
+	}
+	sApp.Running = false
+}
 
+func AppIsRunning() bool {
+	return sApp.Running
 }

+ 2 - 2
chface/http/HttpEntry.go

@@ -5,8 +5,8 @@ import (
 	"github.com/gin-gonic/gin"
 )
 
-func ChHttpEntry(eg *gin.Engine) {
+func FaceHttpEntry(eg *gin.Engine) {
 
-	eg.GET("/test1", test.ChApiTest1)
+	eg.GET("/test1", test.FaceApiTest1)
 
 }

+ 1 - 1
chface/http/test/TestMisc.go

@@ -2,7 +2,7 @@ package test
 
 import "github.com/gin-gonic/gin"
 
-func ChApiTest1(c *gin.Context) { // /ping是路由
+func FaceApiTest1(c *gin.Context) { // /ping是路由
 	//输出json结果给调用方
 	c.JSON(200, gin.H{
 		"message": "test 1 ok",

+ 13 - 4
chfoot/ChFootMain.go

@@ -1,14 +1,23 @@
 package main
 
 import (
-	"chathub/chbase"
+	"chathub/chfoot/core"
 	"fmt"
+	"github.com/etlibgo/et"
+	"time"
 )
 
 func main() {
-	fmt.Println("ch chfoot began")
+	fmt.Println("foot began")
 
-	chbase.ChCommonTest()
+	fmt.Println(et.StrPadLeft("et pad left", "0", 20))
 
-	fmt.Println("ch chfoot ended")
+	core.AppPrepare()
+	core.AppStart()
+
+	for core.AppIsRunning() {
+		time.Sleep(time.Duration(100) * time.Millisecond)
+	}
+
+	fmt.Println("foot ended")
 }

+ 53 - 0
chfoot/core/App.go

@@ -0,0 +1,53 @@
+package core
+
+import (
+	"chathub/chfoot/http"
+	"fmt"
+
+	"github.com/gin-gonic/gin"
+)
+
+var sApp = struct {
+	Running bool
+}{
+	Running: false,
+}
+
+func AppPrepare() {
+
+}
+
+func AppStart() {
+
+	if sApp.Running {
+		return
+	}
+
+	sApp.Running = true
+
+	eg := gin.Default()
+
+	http.FootHttpEntry(eg)
+
+	eg.GET("/ping", func(c *gin.Context) { // /ping是路由
+		//输出json结果给调用方
+		c.JSON(200, gin.H{
+			"message": "pong",
+		})
+	})
+
+	go eg.Run(":8081") // 可以从本地的127.0.0.1:8081访问,不填的话,默认是8080端口
+
+	fmt.Println("foot AppStart started")
+}
+
+func AppStop() {
+	if !sApp.Running {
+		return
+	}
+	sApp.Running = false
+}
+
+func AppIsRunning() bool {
+	return sApp.Running
+}

+ 15 - 0
chfoot/http/HttpEntry.go

@@ -0,0 +1,15 @@
+package http
+
+import (
+	"chathub/chfoot/http/chat"
+	"chathub/chfoot/http/test"
+	"github.com/gin-gonic/gin"
+)
+
+func FootHttpEntry(eg *gin.Engine) {
+
+	eg.GET("/test1", test.FootApiTest1)
+
+	eg.GET("/chat_ask", chat.FootApiChatAsk)
+
+}

+ 10 - 0
chfoot/http/chat/ChatHome.go

@@ -0,0 +1,10 @@
+package chat
+
+import "github.com/gin-gonic/gin"
+
+func FootApiChatAsk(c *gin.Context) { // /ping是路由
+	//输出json结果给调用方
+	c.JSON(200, gin.H{
+		"message": "asking",
+	})
+}

+ 10 - 0
chfoot/http/test/TestMisc.go

@@ -0,0 +1,10 @@
+package test
+
+import "github.com/gin-gonic/gin"
+
+func FootApiTest1(c *gin.Context) { // /ping是路由
+	//输出json结果给调用方
+	c.JSON(200, gin.H{
+		"message": "test 1 ok",
+	})
+}

+ 0 - 0
out/cfg.txt