start

package
v0.0.0-...-f4276bb Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "start",
	Short: "vblog项目后端",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {

		switch configType {
		case "env":
			_, err := conf.LoadConfigFromEnv()
			cobra.CheckErr(err)
		default:

			_, err := conf.LoadConfigFromToml(configFile)
			cobra.CheckErr(err)
		}

		r := gin.Default()
		logger.L().Debug().Msgf("controllers: %s", ioc.ShowConntrollers())
		logger.L().Debug().Msgf("apis: %s", ioc.ShowApis())

		err := ioc.InitController()
		cobra.CheckErr(err)
		err = ioc.InitHttpApi("/vblog/api/v1", r)
		cobra.CheckErr(err)

		httpServer := protocol.NewHttp(r)
		go func() {
			herr := httpServer.Start()
			if herr != http.ErrServerClosed {
				cobra.CheckErr(herr)
			}
		}()

		grpcServer := protocol.NewGrpc()
		go func() {
			gerr := grpcServer.Start()
			cobra.CheckErr(gerr)
		}()

		err = libioc.InitIocObject()
		cobra.CheckErr(err)

		ch := make(chan os.Signal, 1)

		signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP, syscall.SIGQUIT)

		s := <-ch
		logger.L().Info().Msgf("receive os signal: %s, exit ...", s)

		ctx := context.Background()
		httpServer.Stop(ctx)
		grpcServer.Stop(ctx)

		conf.C().MySQL.Close()
	},
}

root command vblog-api start

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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