diff --git a/11.yaml b/11.yaml index b573b34..ddfa8da 100644 --- a/11.yaml +++ b/11.yaml @@ -34,6 +34,13 @@ mongo: db: test max_open: 100 MaxIdle: 99 +ws_server_conf: + type: gateway + id: 1 + ipadress: :9850 + zkserver: + - "49.235.25.67 + ca_cert: "" client_cert: "" client_key: "" diff --git a/config/config.go b/config/config.go index 0b86756..01dbb7f 100644 --- a/config/config.go +++ b/config/config.go @@ -5,6 +5,8 @@ import ( "os" "runtime" + wsConf "tcptemplate/config" + "gopkg.in/yaml.v2" ) @@ -23,6 +25,7 @@ type ConfAPI struct { ElasticSerach ElasticSearch `yaml:"elasticsearch"` Mysql1 MysqlConfig `yaml:"mysql1"` // 认证配置 MongoConf MongoConfig `yaml:"mongo"` + WsServerConf wsConf.Config `yaml:"ws_server_conf"` CaCert string `yaml:"ca_cert"` ClientCert string `yaml:"client_cert"` ClientKey string `yaml:"client_key"'` @@ -83,6 +86,7 @@ func Init(path string) error { } stat, _ := file.Stat() filec := make([]byte, stat.Size()) + log.Print(filec) file.Read(filec) e = yaml.Unmarshal(filec, &gConf) if nil != e { diff --git a/main.go b/main.go index ef68048..78ecb50 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,8 @@ import ( "log" "strconv" + "tcptemplate/network" + "github.com/gin-gonic/gin" ginSwagger "github.com/swaggo/gin-swagger" // gin-swagger middleware "github.com/swaggo/gin-swagger/swaggerFiles" @@ -34,9 +36,8 @@ func CORSMiddleware(c *gin.Context) { c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") if config.ApiConfig().RunMode == "release" { c.Writer.Header().Set("Access-Control-Allow-Origin", "https://testingcloud.club") - } else { - c.Writer.Header().Set("Access-Control-Allow-Origin", "http://127.0.0.1") + c.Writer.Header().Set("Access-Control-Allow-Origin", "http://127.0.0.1:8080") } c.Writer.Header().Set("Access-Control-Max-Age", "86400") c.Writer.Header().Set("Access-Control-Allow-Headers", @@ -101,7 +102,18 @@ func main() { store := sessions.NewCookieStore([]byte("secret123")) r.Use(sessions.Middleware("sess_store", store)) r.Use(CORSMiddleware) // Cross domain + + go func () { + + server := network.ServerFactory("0.0.0.0",config.ApiConfig().WsServerConf) + + server.SetHandler(nil) + e := server.Run() + if nil != e { + } + }() go func() { + // programatically set swagger info r := gin.New() // use ginSwagger middleware to serve the API docs @@ -205,6 +217,8 @@ 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/model/port.go b/model/port.go index 12d453a..e7cb3c1 100644 --- a/model/port.go +++ b/model/port.go @@ -35,7 +35,6 @@ func MysqlToElasticSearchMapping(types string, Key string) string { } return "" } - /* "settings":{ "number_of_shards":1, @@ -121,7 +120,6 @@ func CreateIndexFromMysqlTable(tblname string) error { "properties": props, }, } - for _, v := range columns { props[v.Field] = map[string]string{"type": MysqlToElasticSearchMapping(v.Type, v.Key)} } diff --git a/test/goroutine_test.go b/test/goroutine_test.go index a43b554..a6a3734 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-02 00:32:36 + * @LastEditTime: 2021-08-15 23:15:46 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \background\test\goroutine_test.go @@ -68,6 +68,23 @@ func TestChanel(t *testing.T){ } +func TestTimeoutContext(t * testing.T){ + ctx,_ := context.WithTimeout(context.Background(), time.Second) + + go func () { + for { + select { + case <-ctx.Done(): + t.Logf("exit") + return + case <- time.After(2 * time.Second) : + t.Logf("time out ") + } + } + }() + + time.Sleep(5 * time.Second) +} func TestContext(t *testing.T){ ctx,cancel := context.WithCancel(context.Background()) @@ -108,5 +125,7 @@ func TestContext(t *testing.T){ }() time.Sleep(5 * time.Second) cancel() + + t.Logf("finish") } \ No newline at end of file