From f27ae731bbcc986571a1afccaf3eb5786ff28e67 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Thu, 26 Aug 2021 00:53:20 +0800 Subject: [PATCH] no message --- controller/blog.go | 1 + main.go | 23 ++++++++++++++++++----- test/goroutine_test.go | 21 ++++++++++++++------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 300b42b..28255dc 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -127,6 +127,7 @@ func GetArticleCount(c *gin.Context) { } func GetArticle(c *gin.Context) { + resp := RespBase{Msg: "FAIL", Status: 211} sid := c.Param("id") var id int diff --git a/main.go b/main.go index 78ecb50..8e791de 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "log" "strconv" + "tcptemplate/logger" "tcptemplate/network" "github.com/gin-gonic/gin" @@ -92,6 +93,21 @@ func InitLogs() { logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile) } +type WsHandle struct{ + +} +func (this WsHandle) OnDisConected(*network.ConnectionContext) { + +} +func (this WsHandle) OnConected(c *network.ConnectionContext) { + log.Print(c.IpAdress,c.Cnntime) +} +func (this WsHandle) OnDataRecv(p *network.ConnectionContext, dat []byte) { + log.Print(p.IpAdress) + logger.LogRealeaseInfo(string(dat)) +} + + func main() { InitConfig() InitLogs() @@ -104,10 +120,8 @@ func main() { r.Use(CORSMiddleware) // Cross domain go func () { - server := network.ServerFactory("0.0.0.0",config.ApiConfig().WsServerConf) - - server.SetHandler(nil) + server.SetHandle(WsHandle{}) e := server.Run() if nil != e { } @@ -217,8 +231,7 @@ func main() { openapi.POST("/ddl2markdown", openapiController.DDL2Markdown) // sql ddl转markdown 文档 openapi.POST("/ui2css", openapiController.UI2CSS) // qt ui文件转css文档 } - - + e := r.Run(":" + strconv.Itoa(config.GetPort())) if nil != e { log.Print(e.Error()) diff --git a/test/goroutine_test.go b/test/goroutine_test.go index a6a3734..6e0918d 100644 --- a/test/goroutine_test.go +++ b/test/goroutine_test.go @@ -1,7 +1,7 @@ /* * @Author: your name * @Date: 2021-08-02 00:02:17 - * @LastEditTime: 2021-08-15 23:15:46 + * @LastEditTime: 2021-08-24 23:18:40 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \background\test\goroutine_test.go @@ -68,23 +68,30 @@ func TestChanel(t *testing.T){ } +type TestInherit struct{ + context.Context + x int32 + +} func TestTimeoutContext(t * testing.T){ - ctx,_ := context.WithTimeout(context.Background(), time.Second) + ctx,_ := context.WithTimeout(context.Background(), time.Second * 1) + aa := TestInherit{ctx,1} - go func () { + go func (aa *TestInherit) { for { select { - case <-ctx.Done(): + case <-aa.Done(): t.Logf("exit") return - case <- time.After(2 * time.Second) : + case <- time.After(5 * time.Second) : t.Logf("time out ") } } - }() + }(&aa) - time.Sleep(5 * time.Second) + time.Sleep(10 * time.Second) } + func TestContext(t *testing.T){ ctx,cancel := context.WithCancel(context.Background())