cmd

package
v0.0.0-...-6a8978f Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2022 License: MIT Imports: 12 Imported by: 0

README

程序CLI

.vblog-api start -t file -f etc/config.toml

cobra

命令行的CLI库, 用于编写CLI风格的命令

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "vblog",
	Short: "微博客系统后台API Server",
	Long:  "微博客系统后台API Server",
	RunE: func(cmd *cobra.Command, args []string) error {
		if vers {
			fmt.Println(version.FullVersion())
			return nil
		}
		return cmd.Help()
	},
}

RootCmd represents the base command when called without any subcommands

View Source
var StartCmd = &cobra.Command{
	Use:   "start",
	Short: "启动 API Server",
	Long:  "启动 API Server",
	RunE: func(cmd *cobra.Command, args []string) error {

		if err := loadConfig(); err != nil {
			return err
		}

		loadGlobal()

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

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

		http := protocol.NewHTTP()

		wg := &sync.WaitGroup{}
		wg.Add(1)
		go func() {

			defer wg.Done()

			for v := range ch {
				zap.L().Infof("receive signal: %s, stop service", v)

				switch v {
				case syscall.SIGHUP:
					if err := loadConfig(); err != nil {
						zap.L().Errorf("reload config error, %s", err)
					}
				default:

					ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
					defer cancel()
					http.Stop(ctx)
				}

				return
			}
		}()

		if err := http.Start(); err != nil {
			return err
		}

		wg.Wait()

		return nil
	},
}

StartCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

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