新增单进程模式
This commit is contained in:
1 parent
669a524153
commit
6136e57919
73 files changed
+1900
-153
No files matched your search
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
cfg "hk4e/common/config"
|
||||
"hk4e/dispatch/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -15,7 +16,8 @@ func DispatchCmd() *cobra.Command {
|
||||
Use: "dispatch",
|
||||
Short: "dispatch server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), configFile)
|
||||
cfg.InitConfig(configFile)
|
||||
return app.Run(context.Background())
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
cfg "hk4e/common/config"
|
||||
"hk4e/gate/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -15,7 +16,8 @@ func GateCmd() *cobra.Command {
|
||||
Use: "gate",
|
||||
Short: "gate server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), configFile)
|
||||
cfg.InitConfig(configFile)
|
||||
return app.Run(context.Background())
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
cfg "hk4e/common/config"
|
||||
"hk4e/gm/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -14,7 +15,8 @@ func GMCmd() *cobra.Command {
|
||||
Use: "gm",
|
||||
Short: "gm server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), configFile)
|
||||
cfg.InitConfig(configFile)
|
||||
return app.Run(context.Background())
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
cfg "hk4e/common/config"
|
||||
"hk4e/gs/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -15,7 +16,8 @@ func GSCmd() *cobra.Command {
|
||||
Use: "gs",
|
||||
Short: "game server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), configFile)
|
||||
cfg.InitConfig(configFile)
|
||||
return app.Run(context.Background())
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
cfg "hk4e/common/config"
|
||||
"hk4e/multi/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -15,7 +16,8 @@ func MultiCmd() *cobra.Command {
|
||||
Use: "multi",
|
||||
Short: "multi server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), configFile)
|
||||
cfg.InitConfig(configFile)
|
||||
return app.Run(context.Background())
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
|
||||
|
||||
+4
-60
@@ -1,17 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"context"
|
||||
|
||||
"hk4e/cmd/nats"
|
||||
cfg "hk4e/common/config"
|
||||
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -21,60 +15,10 @@ func NatsCmd() *cobra.Command {
|
||||
Use: "nats",
|
||||
Short: "nats server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunNatsServer(configFile)
|
||||
cfg.InitConfig(configFile)
|
||||
return nats.RunNatsServer(context.Background())
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
|
||||
return c
|
||||
}
|
||||
|
||||
func RunNatsServer(configFile string) error {
|
||||
cfg.InitConfig(configFile)
|
||||
natsAddr := strings.ReplaceAll(cfg.GetConfig().MQ.NatsUrl, "nats://", "")
|
||||
if strings.Contains(natsAddr, ",") {
|
||||
return errors.New("not support nats cluster")
|
||||
}
|
||||
split := strings.Split(natsAddr, ":")
|
||||
if len(split) != 2 {
|
||||
return errors.New("nats addr format error")
|
||||
}
|
||||
host := split[0]
|
||||
port, err := strconv.Atoi(split[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts := &server.Options{
|
||||
Host: host,
|
||||
Port: port,
|
||||
NoLog: false,
|
||||
NoSigs: true,
|
||||
MaxControlLine: 4096,
|
||||
DisableShortFirstPing: true,
|
||||
Trace: true,
|
||||
Debug: true,
|
||||
}
|
||||
natsServer, err := server.NewServer(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
natsServer.ConfigureLogger()
|
||||
go natsServer.Start()
|
||||
ok := natsServer.ReadyForConnections(time.Second * 5)
|
||||
if !ok {
|
||||
return errors.New("nats server start error")
|
||||
}
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
s := <-c
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
return nil
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
cfg "hk4e/common/config"
|
||||
"hk4e/node/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -14,7 +15,8 @@ func NodeCmd() *cobra.Command {
|
||||
Use: "node",
|
||||
Short: "node server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), configFile)
|
||||
cfg.InitConfig(configFile)
|
||||
return app.Run(context.Background())
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
|
||||
|
||||
+4
-1
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
cfg "hk4e/common/config"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"context"
|
||||
@@ -15,7 +17,8 @@ func RobotCmd() *cobra.Command {
|
||||
Use: "robot",
|
||||
Short: "robot server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), configFile)
|
||||
cfg.InitConfig(configFile)
|
||||
return app.Run(context.Background())
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
|
||||
|
||||
Reference in new issue
Block a user