From 2e2076ff49973285be70d299ffd10439ad965633 Mon Sep 17 00:00:00 2001 From: jiangbiao <154238669@qq.com> Date: Tue, 29 Jun 2021 15:00:53 +0800 Subject: [PATCH 1/3] zookeeper support --- .idea/.gitignore | 8 ++++++ .idea/gochat.iml | 9 ++++++ .idea/modules.xml | 8 ++++++ .idea/vcs.xml | 6 ++++ api/rpc/rpc.go | 21 ++++++++++---- config/config.go | 12 ++++++-- config/dev/common.toml | 8 ++++++ config/prod/common.toml | 8 ++++++ connect/rpc.go | 59 +++++++++++++++++++++++++++++----------- db/gochat.sqlite3 | Bin 24576 -> 24576 bytes go.mod | 1 + logic/publish.go | 39 ++++++++++++++++++-------- main.go | 38 ++++++++++++-------------- main/api.go | 23 ++++++++++++++++ main/connecttcp.go | 23 ++++++++++++++++ main/connectws.go | 23 ++++++++++++++++ main/logic.go | 23 ++++++++++++++++ main/site.go | 24 ++++++++++++++++ main/task.go | 23 ++++++++++++++++ task/rpc.go | 29 ++++++++++++++++++-- 20 files changed, 327 insertions(+), 58 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/gochat.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 main/api.go create mode 100644 main/connecttcp.go create mode 100644 main/connectws.go create mode 100644 main/logic.go create mode 100644 main/site.go create mode 100644 main/task.go diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..73f69e09 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/gochat.iml b/.idea/gochat.iml new file mode 100644 index 00000000..5e764c4f --- /dev/null +++ b/.idea/gochat.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..20e5a752 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/api/rpc/rpc.go b/api/rpc/rpc.go index a8dfa405..131bc7ea 100644 --- a/api/rpc/rpc.go +++ b/api/rpc/rpc.go @@ -24,12 +24,21 @@ var RpcLogicObj *RpcLogic func InitLogicRpcClient() { once.Do(func() { - d := client.NewEtcdV3Discovery( - config.Conf.Common.CommonEtcd.BasePath, - config.Conf.Common.CommonEtcd.ServerPathLogic, - []string{config.Conf.Common.CommonEtcd.Host}, - nil, - ) + var d client.ServiceDiscovery + if config.Conf.Common.Registy == "etcd" { + d = client.NewEtcdV3Discovery( + config.Conf.Common.CommonEtcd.BasePath, + config.Conf.Common.CommonEtcd.ServerPathLogic, + []string{config.Conf.Common.CommonEtcd.Host}, + nil, + ) + } + if config.Conf.Common.Registy == "zookeeper" { + d = client.NewZookeeperDiscovery(config.Conf.Common.CommonZookeeper.BasePath, + config.Conf.Common.CommonZookeeper.ServerPathLogic, + []string{config.Conf.Common.CommonZookeeper.Host}, + nil) + } LogicRpcClient = client.NewXClient(config.Conf.Common.CommonEtcd.ServerPathLogic, client.Failtry, client.RandomSelect, d, client.DefaultOption) RpcLogicObj = new(RpcLogic) }) diff --git a/config/config.go b/config/config.go index 261ca3d2..d1b6741b 100644 --- a/config/config.go +++ b/config/config.go @@ -131,6 +131,12 @@ type CommonEtcd struct { ServerPathLogic string `mapstructure:"serverPathLogic"` ServerPathConnect string `mapstructure:"serverPathConnect"` } +type CommonZookeeper struct { + Host string `mapstructure:"host"` + BasePath string `mapstructure:"basePath"` + ServerPathLogic string `mapstructure:"serverPathLogic"` + ServerPathConnect string `mapstructure:"serverPathConnect"` +} type CommonRedis struct { RedisAddress string `mapstructure:"redisAddress"` @@ -139,8 +145,10 @@ type CommonRedis struct { } type Common struct { - CommonEtcd CommonEtcd `mapstructure:"common-etcd"` - CommonRedis CommonRedis `mapstructure:"common-redis"` + Registy string `mapstructure:"registy"` + CommonEtcd CommonEtcd `mapstructure:"common-etcd"` + CommonZookeeper CommonZookeeper `mapstructure:"common-zookeeper"` + CommonRedis CommonRedis `mapstructure:"common-redis"` } type ConnectBase struct { diff --git a/config/dev/common.toml b/config/dev/common.toml index 75fedb41..3fd1ff2c 100644 --- a/config/dev/common.toml +++ b/config/dev/common.toml @@ -1,9 +1,17 @@ +registy = "zookeeper" + [common-etcd] host = "127.0.0.1:2379" basePath = "/gochat_srv" serverPathLogic = "LogicRpc" serverPathConnect = "ConnectRpc" +[common-zookeeper] +host = "127.0.0.1:2181" +basePath = "/gochat_srv" +serverPathLogic = "LogicRpc" +serverPathConnect = "ConnectRpc" + [common-redis] redisAddress = "127.0.0.1:6379" redisPassword = "" diff --git a/config/prod/common.toml b/config/prod/common.toml index 75fedb41..3fd1ff2c 100644 --- a/config/prod/common.toml +++ b/config/prod/common.toml @@ -1,9 +1,17 @@ +registy = "zookeeper" + [common-etcd] host = "127.0.0.1:2379" basePath = "/gochat_srv" serverPathLogic = "LogicRpc" serverPathConnect = "ConnectRpc" +[common-zookeeper] +host = "127.0.0.1:2181" +basePath = "/gochat_srv" +serverPathLogic = "LogicRpc" +serverPathConnect = "ConnectRpc" + [common-redis] redisAddress = "127.0.0.1:6379" redisPassword = "" diff --git a/connect/rpc.go b/connect/rpc.go index 797626f7..f0d0b01e 100644 --- a/connect/rpc.go +++ b/connect/rpc.go @@ -30,12 +30,21 @@ type RpcConnect struct { func (c *Connect) InitLogicRpcClient() (err error) { once.Do(func() { - d := client.NewEtcdV3Discovery( - config.Conf.Common.CommonEtcd.BasePath, - config.Conf.Common.CommonEtcd.ServerPathLogic, - []string{config.Conf.Common.CommonEtcd.Host}, - nil, - ) + var d client.ServiceDiscovery + if config.Conf.Common.Registy == "etcd" { + d = client.NewEtcdV3Discovery( + config.Conf.Common.CommonEtcd.BasePath, + config.Conf.Common.CommonEtcd.ServerPathLogic, + []string{config.Conf.Common.CommonEtcd.Host}, + nil, + ) + } + if config.Conf.Common.Registy == "zookeeper" { + d = client.NewZookeeperDiscovery(config.Conf.Common.CommonZookeeper.BasePath, + config.Conf.Common.CommonZookeeper.ServerPathLogic, + []string{config.Conf.Common.CommonZookeeper.Host}, + nil) + } logicRpcClient = client.NewXClient(config.Conf.Common.CommonEtcd.ServerPathLogic, client.Failtry, client.RandomSelect, d, client.DefaultOption) }) if logicRpcClient == nil { @@ -168,16 +177,34 @@ func (c *Connect) createConnectTcpRpcServer(network string, addr string) { } func addRegistryPlugin(s *server.Server, network string, addr string) { - r := &serverplugin.EtcdV3RegisterPlugin{ - ServiceAddress: network + "@" + addr, - EtcdServers: []string{config.Conf.Common.CommonEtcd.Host}, - BasePath: config.Conf.Common.CommonEtcd.BasePath, - Metrics: metrics.NewRegistry(), - UpdateInterval: time.Minute, + + if config.Conf.Common.Registy == "etcd" { + r := &serverplugin.EtcdV3RegisterPlugin{ + ServiceAddress: network + "@" + addr, + EtcdServers: []string{config.Conf.Common.CommonEtcd.Host}, + BasePath: config.Conf.Common.CommonEtcd.BasePath, + Metrics: metrics.NewRegistry(), + UpdateInterval: time.Minute, + } + err := r.Start() + if err != nil { + logrus.Fatal(err) + } + s.Plugins.Add(r) } - err := r.Start() - if err != nil { - logrus.Fatal(err) + if config.Conf.Common.Registy == "zookeeper" { + r := &serverplugin.ZooKeeperRegisterPlugin{ + ServiceAddress: network + "@" + addr, + ZooKeeperServers: []string{config.Conf.Common.CommonZookeeper.Host}, + BasePath: config.Conf.Common.CommonZookeeper.BasePath, + Metrics: metrics.NewRegistry(), + UpdateInterval: time.Minute, + } + err := r.Start() + if err != nil { + logrus.Fatal(err) + } + s.Plugins.Add(r) } - s.Plugins.Add(r) + } diff --git a/db/gochat.sqlite3 b/db/gochat.sqlite3 index e581a0cfe0a096a3cfbeba960a319b0a46673f5b..14c44767654f3d7a7439253f7e1b3187bcaf7705 100644 GIT binary patch delta 290 zcmY+Frb7+KO1HB#qr^&UZMoj?FsuxXa*a?=*!ZKb*YQ&medv5_o}2*vz`@IumVA zd~ZLDc$)ODE+%)=o7;PXGD_#XF}8_S6M|B~jU^S9oGR){MI;-oBP2OQGbBHdx>Qt3 zpBJ9A)!LXNbS2^_UAv)~PF3^U4l&jyc*F)#DJ7NBs+QK(9wm+=R!Y);7U59YHFAhr*YkQ%exFC!2E1hWA^1`x9bQ2GzZ5Ex4U diff --git a/go.mod b/go.mod index adc963ab..8b6c2eda 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/bwmarrin/snowflake v0.3.0 github.com/gin-gonic/gin v1.4.0 github.com/go-redis/redis v6.15.2+incompatible + github.com/google/uuid v1.1.1 // indirect github.com/gorilla/websocket v1.4.0 github.com/jinzhu/gorm v1.9.10 github.com/pkg/errors v0.8.1 diff --git a/logic/publish.go b/logic/publish.go index 39e319dd..5954313e 100644 --- a/logic/publish.go +++ b/logic/publish.go @@ -69,18 +69,35 @@ func (logic *Logic) createRpcServer(network string, addr string) { } func (logic *Logic) addRegistryPlugin(s *server.Server, network string, addr string) { - r := &serverplugin.EtcdV3RegisterPlugin{ - ServiceAddress: network + "@" + addr, - EtcdServers: []string{config.Conf.Common.CommonEtcd.Host}, - BasePath: config.Conf.Common.CommonEtcd.BasePath, - Metrics: metrics.NewRegistry(), - UpdateInterval: time.Minute, - } - err := r.Start() - if err != nil { - logrus.Fatal(err) + if config.Conf.Common.Registy == "etcd" { + r := &serverplugin.EtcdV3RegisterPlugin{ + ServiceAddress: network + "@" + addr, + EtcdServers: []string{config.Conf.Common.CommonEtcd.Host}, + BasePath: config.Conf.Common.CommonEtcd.BasePath, + Metrics: metrics.NewRegistry(), + UpdateInterval: time.Minute, + } + err := r.Start() + if err != nil { + logrus.Fatal(err) + } + s.Plugins.Add(r) + } + if config.Conf.Common.Registy == "zookeeper" { + r := &serverplugin.ZooKeeperRegisterPlugin{ + ServiceAddress: network + "@" + addr, + ZooKeeperServers: []string{config.Conf.Common.CommonZookeeper.Host}, + BasePath: config.Conf.Common.CommonZookeeper.BasePath, + Metrics: metrics.NewRegistry(), + UpdateInterval: time.Minute, + } + err := r.Start() + if err != nil { + logrus.Fatal(err) + } + s.Plugins.Add(r) } - s.Plugins.Add(r) + } func (logic *Logic) RedisPublishChannel(serverId string, toUserId int, msg []byte) (err error) { diff --git a/main.go b/main.go index 99c72877..fc233db1 100644 --- a/main.go +++ b/main.go @@ -8,11 +8,9 @@ package main import ( "flag" "fmt" - "gochat/api" - "gochat/connect" - "gochat/logic" "gochat/site" - "gochat/task" + + //"gochat/task" "os" "os/signal" "syscall" @@ -23,23 +21,23 @@ func main() { flag.StringVar(&module, "module", "", "assign run module") flag.Parse() fmt.Println(fmt.Sprintf("start run %s module", module)) - switch module { - case "logic": - logic.New().Run() - case "connect_websocket": - connect.New().Run() - case "connect_tcp": - connect.New().RunTcp() - case "task": - task.New().Run() - case "api": - api.New().Run() - case "site": + //switch module { + //case "logic": + // logic.New().Run() + //case "connect_websocket": + // connect.New().Run() + //case "connect_tcp": + // connect.New().RunTcp() + //case "task": + // task.New().Run() + //case "api": + // api.New().Run() + //case "site": site.New().Run() - default: - fmt.Println("exiting,module param error!") - return - } + //default: + // fmt.Println("exiting,module param error!") + // return + //} fmt.Println(fmt.Sprintf("run %s module done!", module)) quit := make(chan os.Signal) signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) diff --git a/main/api.go b/main/api.go new file mode 100644 index 00000000..14659f11 --- /dev/null +++ b/main/api.go @@ -0,0 +1,23 @@ +/** + * Created by lock + * Date: 2019-08-09 + * Time: 10:56 + */ +package main + +import ( + "fmt" + "gochat/api" + //"gochat/task" + "os" + "os/signal" + "syscall" +) + +func main() { + api.New().Run() + quit := make(chan os.Signal) + signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + <-quit + fmt.Println("Server exiting") +} diff --git a/main/connecttcp.go b/main/connecttcp.go new file mode 100644 index 00000000..8b4ab20b --- /dev/null +++ b/main/connecttcp.go @@ -0,0 +1,23 @@ +/** + * Created by lock + * Date: 2019-08-09 + * Time: 10:56 + */ +package main + +import ( + "fmt" + "gochat/connect" + //"gochat/task" + "os" + "os/signal" + "syscall" +) + +func main() { + connect.New().RunTcp() + quit := make(chan os.Signal) + signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + <-quit + fmt.Println("Server exiting") +} diff --git a/main/connectws.go b/main/connectws.go new file mode 100644 index 00000000..516ce197 --- /dev/null +++ b/main/connectws.go @@ -0,0 +1,23 @@ +/** + * Created by lock + * Date: 2019-08-09 + * Time: 10:56 + */ +package main + +import ( + "fmt" + "gochat/connect" + //"gochat/task" + "os" + "os/signal" + "syscall" +) + +func main() { + connect.New().Run() + quit := make(chan os.Signal) + signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + <-quit + fmt.Println("Server exiting") +} diff --git a/main/logic.go b/main/logic.go new file mode 100644 index 00000000..2c6222b5 --- /dev/null +++ b/main/logic.go @@ -0,0 +1,23 @@ +/** + * Created by lock + * Date: 2019-08-09 + * Time: 10:56 + */ +package main + +import ( + "fmt" + "gochat/logic" + //"gochat/task" + "os" + "os/signal" + "syscall" +) + +func main() { + logic.New().Run() + quit := make(chan os.Signal) + signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + <-quit + fmt.Println("Server exiting") +} diff --git a/main/site.go b/main/site.go new file mode 100644 index 00000000..f988da5c --- /dev/null +++ b/main/site.go @@ -0,0 +1,24 @@ +/** + * Created by lock + * Date: 2019-08-09 + * Time: 10:56 + */ +package main + +import ( + "fmt" + "gochat/site" + + //"gochat/task" + "os" + "os/signal" + "syscall" +) + +func main() { + site.New().Run() + quit := make(chan os.Signal) + signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + <-quit + fmt.Println("Server exiting") +} diff --git a/main/task.go b/main/task.go new file mode 100644 index 00000000..5be8630c --- /dev/null +++ b/main/task.go @@ -0,0 +1,23 @@ +/** + * Created by lock + * Date: 2019-08-09 + * Time: 10:56 + */ +package main + +import ( + "fmt" + "gochat/task" + //"gochat/task" + "os" + "os/signal" + "syscall" +) + +func main() { + task.New().Run() + quit := make(chan os.Signal) + signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + <-quit + fmt.Println("Server exiting") +} diff --git a/task/rpc.go b/task/rpc.go index 6a3c78b4..a329a5ab 100644 --- a/task/rpc.go +++ b/task/rpc.go @@ -19,8 +19,31 @@ import ( var RpcConnectClientList map[string]client.XClient func (task *Task) InitConnectRpcClient() (err error) { - etcdConfig := config.Conf.Common.CommonEtcd - d := client.NewEtcdV3Discovery(etcdConfig.BasePath, etcdConfig.ServerPathConnect, []string{etcdConfig.Host}, nil) + //etcdConfig := config.Conf.Common.CommonEtcd + //zookkperConfig := config.Conf.Common.CommonZookeeper + ////d := client.NewEtcdV3Discovery(etcdConfig.BasePath, etcdConfig.ServerPathConnect, []string{etcdConfig.Host}, nil) + //d := client.NewZookeeperDiscovery(zookkperConfig.BasePath, zookkperConfig.ServerPathConnect, []string{zookkperConfig.Host}, nil) + + + var d client.ServiceDiscovery + var ServerPathConnect string + if config.Conf.Common.Registy == "etcd" { + ServerPathConnect=config.Conf.Common.CommonEtcd.ServerPathConnect + d = client.NewEtcdV3Discovery( + config.Conf.Common.CommonEtcd.BasePath, + config.Conf.Common.CommonEtcd.ServerPathConnect, + []string{config.Conf.Common.CommonEtcd.Host}, + nil, + ) + } + if config.Conf.Common.Registy == "zookeeper" { + ServerPathConnect=config.Conf.Common.CommonZookeeper.ServerPathConnect + d = client.NewZookeeperDiscovery(config.Conf.Common.CommonZookeeper.BasePath, + config.Conf.Common.CommonZookeeper.ServerPathConnect, + []string{config.Conf.Common.CommonZookeeper.Host}, + nil) + } + if len(d.GetServices()) <= 0 { logrus.Panicf("no etcd server find!") } @@ -35,7 +58,7 @@ func (task *Task) InitConnectRpcClient() (err error) { } d := client.NewPeer2PeerDiscovery(connectConf.Key, "") //under serverId - RpcConnectClientList[serverId] = client.NewXClient(etcdConfig.ServerPathConnect, client.Failtry, client.RandomSelect, d, client.DefaultOption) + RpcConnectClientList[serverId] = client.NewXClient(ServerPathConnect, client.Failtry, client.RandomSelect, d, client.DefaultOption) logrus.Infof("InitConnectRpcClient addr %s, v %+v", connectConf.Key, RpcConnectClientList[serverId]) } return From 56f0846a12891206bcd6bbb84b92c129ee943b83 Mon Sep 17 00:00:00 2001 From: jiangbiao <154238669@qq.com> Date: Tue, 29 Jun 2021 15:05:49 +0800 Subject: [PATCH 2/3] delete some no use file --- main/api.go | 23 ----------------------- main/connecttcp.go | 23 ----------------------- main/connectws.go | 23 ----------------------- main/logic.go | 23 ----------------------- main/site.go | 24 ------------------------ main/task.go | 23 ----------------------- 6 files changed, 139 deletions(-) delete mode 100644 main/api.go delete mode 100644 main/connecttcp.go delete mode 100644 main/connectws.go delete mode 100644 main/logic.go delete mode 100644 main/site.go delete mode 100644 main/task.go diff --git a/main/api.go b/main/api.go deleted file mode 100644 index 14659f11..00000000 --- a/main/api.go +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Created by lock - * Date: 2019-08-09 - * Time: 10:56 - */ -package main - -import ( - "fmt" - "gochat/api" - //"gochat/task" - "os" - "os/signal" - "syscall" -) - -func main() { - api.New().Run() - quit := make(chan os.Signal) - signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - <-quit - fmt.Println("Server exiting") -} diff --git a/main/connecttcp.go b/main/connecttcp.go deleted file mode 100644 index 8b4ab20b..00000000 --- a/main/connecttcp.go +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Created by lock - * Date: 2019-08-09 - * Time: 10:56 - */ -package main - -import ( - "fmt" - "gochat/connect" - //"gochat/task" - "os" - "os/signal" - "syscall" -) - -func main() { - connect.New().RunTcp() - quit := make(chan os.Signal) - signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - <-quit - fmt.Println("Server exiting") -} diff --git a/main/connectws.go b/main/connectws.go deleted file mode 100644 index 516ce197..00000000 --- a/main/connectws.go +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Created by lock - * Date: 2019-08-09 - * Time: 10:56 - */ -package main - -import ( - "fmt" - "gochat/connect" - //"gochat/task" - "os" - "os/signal" - "syscall" -) - -func main() { - connect.New().Run() - quit := make(chan os.Signal) - signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - <-quit - fmt.Println("Server exiting") -} diff --git a/main/logic.go b/main/logic.go deleted file mode 100644 index 2c6222b5..00000000 --- a/main/logic.go +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Created by lock - * Date: 2019-08-09 - * Time: 10:56 - */ -package main - -import ( - "fmt" - "gochat/logic" - //"gochat/task" - "os" - "os/signal" - "syscall" -) - -func main() { - logic.New().Run() - quit := make(chan os.Signal) - signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - <-quit - fmt.Println("Server exiting") -} diff --git a/main/site.go b/main/site.go deleted file mode 100644 index f988da5c..00000000 --- a/main/site.go +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Created by lock - * Date: 2019-08-09 - * Time: 10:56 - */ -package main - -import ( - "fmt" - "gochat/site" - - //"gochat/task" - "os" - "os/signal" - "syscall" -) - -func main() { - site.New().Run() - quit := make(chan os.Signal) - signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - <-quit - fmt.Println("Server exiting") -} diff --git a/main/task.go b/main/task.go deleted file mode 100644 index 5be8630c..00000000 --- a/main/task.go +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Created by lock - * Date: 2019-08-09 - * Time: 10:56 - */ -package main - -import ( - "fmt" - "gochat/task" - //"gochat/task" - "os" - "os/signal" - "syscall" -) - -func main() { - task.New().Run() - quit := make(chan os.Signal) - signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - <-quit - fmt.Println("Server exiting") -} From dffddbf61b1f600be9a7b6b9c24d4c8928f00ad2 Mon Sep 17 00:00:00 2001 From: jiangbiao <154238669@qq.com> Date: Tue, 29 Jun 2021 15:08:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index fc233db1..d4f6f74c 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,11 @@ package main import ( "flag" "fmt" + "gochat/api" + "gochat/connect" + "gochat/logic" "gochat/site" + "gochat/task" //"gochat/task" "os" @@ -21,23 +25,23 @@ func main() { flag.StringVar(&module, "module", "", "assign run module") flag.Parse() fmt.Println(fmt.Sprintf("start run %s module", module)) - //switch module { - //case "logic": - // logic.New().Run() - //case "connect_websocket": - // connect.New().Run() - //case "connect_tcp": - // connect.New().RunTcp() - //case "task": - // task.New().Run() - //case "api": - // api.New().Run() - //case "site": + switch module { + case "logic": + logic.New().Run() + case "connect_websocket": + connect.New().Run() + case "connect_tcp": + connect.New().RunTcp() + case "task": + task.New().Run() + case "api": + api.New().Run() + case "site": site.New().Run() - //default: - // fmt.Println("exiting,module param error!") - // return - //} + default: + fmt.Println("exiting,module param error!") + return + } fmt.Println(fmt.Sprintf("run %s module done!", module)) quit := make(chan os.Signal) signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)