server

package
v0.0.0-...-2a2a1f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StartCmd = &cobra.Command{
		Use:     "server",
		Short:   "Start server",
		Example: "jframe server -c ./config.yaml",
		Run: func(cmd *cobra.Command, args []string) {
			logx.PreInit()
			log := logx.NameSpace("cmd.server")
			log.Info("loading config...")
			conf.LoadConfig(configPath)
			log.Info("loading config complete")

			log.Info("init dep...")
			if conf.Get().SentryDsn != "" {
				sentry.Init()
			}
			if conf.Get().MODE == "" || conf.Get().MODE == "debug" {
				logx.Init(zapcore.DebugLevel)
			} else {
				logx.Init(zapcore.InfoLevel)
			}
			defer func() {
				if err := recover(); err != nil {
					log.Errorw("panic", "error", err)
				}
			}()
			log.Info("init dep complete")

			log.Info("init kernel...")
			conn, err := net.Listen("tcp", fmt.Sprintf(":%s", conf.Get().Port))
			if err != nil {
				log.Errorw("failed to listen", "error", err)
				return
			}
			tcpMux := cmux.New(conn)
			log.Infow("start listening", "port", conf.Get().Port)
			k := kernel.New(kernel.Config{})
			k.Map(&conn, &tcpMux)

			k.RegMod(modList.ModList...)
			k.Init()
			log.Info("init kernel complete")

			log.Info("init module...")
			err = k.StartModule()
			if err != nil {
				panic(err)
			}
			log.Info("init module complete")

			log.Info("starting Server...")
			k.Serve()
			go func() {
				_ = tcpMux.Serve()
			}()

			fmt.Println("Server run at:")
			fmt.Printf("-  Local:   http://localhost:%s\n", conf.Get().Port)
			for _, host := range ip.GetLocalHost() {
				fmt.Printf("-  Network: http://%s:%s\n", host, conf.Get().Port)
			}

			quit := make(chan os.Signal, 1)
			signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
			<-quit
			fmt.Println("Shutting down server...")

			err = k.Stop()
			if err != nil {
				panic(err)
			}
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL