multi

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Commands is used to start multiple service simultaneously
	Commands = []*cli.Command{
		{
			Name:      "multi:server",
			Category:  category,
			Usage:     "start multiple service simultaneously",
			UsageText: "multi:server [command options]",
			Action: func(ctx *cli.Context) error {
				var (
					wg  sync.WaitGroup
					sig = make(chan struct{})
				)

				if !util.IsFile(ctx.String("server-cert")) {
					logger.Error("server certificate file not exist")
					return nil
				}

				if !util.IsFile(ctx.String("server-key")) {
					logger.Error("server certificate key file not exist")
					return nil
				}

				if !util.IsFile(ctx.String("ca-cert")) {
					logger.Error("ca certificate file not exist")
					return nil
				}

				wg.Add(3)

				go func() {
					defer wg.Done()
					_ = startHTTPServer(ctx, sig)
				}()

				go func() {
					defer wg.Done()
					_ = startFtpServer(ctx, sig)
				}()

				go func() {
					defer wg.Done()
					_ = startRPCServer(ctx, sig)
				}()

				quit := make(chan os.Signal, 1)
				signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
				<-quit
				close(sig)
				wg.Wait()
				return nil
			},
			Flags: []cli.Flag{

				&cli.StringFlag{
					Name:    "host",
					Aliases: []string{"H"},
					Usage:   "http service listen ip",
					Value:   "0.0.0.0",
				},
				&cli.StringFlag{
					Name:  "server-cert",
					Usage: "certificate file for enable tls/ssl server",
					Value: "server.pem",
				},
				&cli.StringFlag{
					Name:  "server-key",
					Usage: "certificate key file for enable tls/ssl server",
					Value: "server.key",
				},
				&cli.StringFlag{
					Name:  "ca-cert",
					Usage: "certificate key file for enable tls/ssl server",
					Value: "ca.pem",
				},

				&cli.Int64Flag{
					Name:  "http-port",
					Usage: "http service listen port",
					Value: 10985,
				},
				&cli.DurationFlag{
					Name: "http-read-timeout",
					Usage: "http-read-timeout is the maximum duration for reading " +
						"the entire request, including the body",
					Value: 0,
				},
				&cli.DurationFlag{
					Name: "http-read-header-timeout",
					Usage: "http-read-header-timeout is the amount of time allowed " +
						"to read request headers",
					Value: 0,
				},
				&cli.DurationFlag{
					Name: "http-write-timeout",
					Usage: "http-writer-timeout is the maximum duration before timing " +
						"out writes of the response",
					Value: 0,
				},
				&cli.DurationFlag{
					Name: "http-idle-timeout",
					Usage: "http-idle-timeout is the maximum amount of time to wait for " +
						"the next request when keep-alives are enabled",
					Value: 0,
				},
				&cli.DurationFlag{
					Name:  "http-wait-shutdown",
					Usage: "wait time before timeout for closing server",
					Value: 5 * time.Second,
				},
				&cli.IntFlag{
					Name: "http-max-header-bytes",
					Usage: "http-max-header-bytes controls the maximum number of bytes the " +
						"server will read parsing the request header's keys and values, " +
						"including the request line. It does not limit the size of the request body",
					Value: 0,
				},

				&cli.UintFlag{
					Name:  "ftp-port",
					Usage: "ftp server port",
					Value: 2121,
				},
				&cli.StringFlag{
					Name:  "ftp-passive-ip",
					Usage: "ftp client connect to ftp server to transfer data in passive mode",
					Value: "",
				},
				&cli.StringFlag{
					Name:  "ftp-passive-port-range",
					Usage: "ftp server will pick a port random in the range, open the data connection tunnel in passive mode",
					Value: "52013-52114",
				},
				&cli.StringFlag{
					Name:  "ftp-welcome-message",
					Usage: "ftp server welcome message",
					Value: "welcome to bigfile ftp server",
				},

				&cli.IntFlag{
					Name:  "rpc-auth-client",
					Usage: "rpc service client certificate auth type, 0: no client cert, 1: request client cert, 2: require any client cert, 3: verify client cert if given, 4: require and verify client cert",
					Value: 4,
				},
				&cli.Int64Flag{
					Name:  "rpc-port",
					Usage: "rpc service listen port",
					Value: 10986,
				},
			},
			Before: func(ctx *cli.Context) (err error) {
				gin.SetMode(gin.ReleaseMode)
				db := databases.MustNewConnection(&config.DefaultConfig.Database)
				migrate.DefaultMC.SetConnection(db)
				migrate.DefaultMC.Upgrade()
				return nil
			},
		},
	}
)

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