cmd

package
v0.6.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:          os.Args[0],
	Short:        "piping-server",
	Long:         "Infinitely transfer between any device over pure HTTP",
	SilenceUsage: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		if showsVersion {
			fmt.Printf("%s (%s)\n", version.Version, runtime.Version())
			return nil
		}
		logger := log.New(os.Stderr, "", log.LstdFlags|log.Lmicroseconds)
		logger.Printf("Piping Server %s (%s)", version.Version, runtime.Version())
		pipingServer := piping_server.NewServer(logger)
		errCh := make(chan error)
		if enableHttps || enableHttp3 {
			if keyPath == "" {
				return errors.New("--key-path should be specified")
			}
			if crtPath == "" {
				return errors.New("--crt-path should be specified")
			}
			go func() {
				logger.Printf("Listening HTTPS on %d...\n", httpsPort)
				errCh <- http.ListenAndServeTLS(fmt.Sprintf(":%d", httpsPort), crtPath, keyPath, http.HandlerFunc(pipingServer.Handler))
			}()
			if enableHttp3 {
				go func() {
					logger.Printf("Listening HTTP/3 on %d...\n", httpsPort)
					errCh <- http3.ListenAndServeQUIC(fmt.Sprintf(":%d", httpsPort), crtPath, keyPath, http.HandlerFunc(pipingServer.Handler))
				}()
			}
		}
		go func() {
			server := &http.Server{
				Addr:    fmt.Sprintf(":%d", httpPort),
				Handler: h2c.NewHandler(http.HandlerFunc(pipingServer.Handler), &http2.Server{}),
			}
			logger.Printf("Listening HTTP on %d...\n", httpPort)
			errCh <- server.ListenAndServe()
		}()
		return <-errCh
	},
}

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