cmd

package
v0.0.0-...-c8733ce Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const GoVersionFormat = "Built with Go toolchain %s"
View Source
const HelpFooter = "\n" +
	"Submit bug reports, questions, discussions through our repository's\n" +
	"issue tracker at https://github.com/hadi77ir/wsproxy/issues\n"

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "wsproxy [flags] LOCAL REMOTE",
	Short: "wsproxy - yet another websockify implementation, with additional functionality",
	Long: `wsproxy is a utility suited to forward (sometimes called "tunneling")
connections of one transport over another. for example: WebSocket.`,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		logger := cmd.Context().Value("logger").(logging.Logger)
		utils.SetMaxProcs(logger)
	},
	Args:       cobra.MinimumNArgs(2),
	ArgAliases: []string{"local", "remote"},
	Run: func(cmd *cobra.Command, args []string) {
		logger := cmd.Context().Value("logger").(logging.Logger)

		sigChan := make(chan os.Signal, 1)
		signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

		if len(args) != 2 {
			logger.Log(logging.ErrorLevel, "incorrect number of args: =", len(args), ", has to be = 2")
			return
		}

		local := args[0]
		remote := args[1]

		localOptions, err := cmd.Flags().GetStringArray("lo")
		if err != nil {
			logger.Log(logging.ErrorLevel, "error reading local options:", err)
			return
		}
		remoteOptions, err := cmd.Flags().GetStringArray("ro")
		if err != nil {
			logger.Log(logging.ErrorLevel, "error reading remote options:", err)
			return
		}

		parsedLocalOptions, err := utils.ParseTransportParamsFromFlags(localOptions)
		if err != nil {
			logger.Log(logging.ErrorLevel, "error reading local transport parameters:", err)
			return
		}
		parsedRemoteOptions, err := utils.ParseTransportParamsFromFlags(remoteOptions)
		if err != nil {
			logger.Log(logging.ErrorLevel, "error parsing remote transport parameters:", err)
			return
		}

		localEndpoint := proxy.Endpoint{Addr: local, TransportParams: parsedLocalOptions}
		remoteEndpoint := proxy.Endpoint{Addr: remote, TransportParams: parsedRemoteOptions}
		instance := proxy.NewProxy(localEndpoint, remoteEndpoint, logger, sigChan)

		if err := instance.Run(); err != nil {
			logger.Log(logging.ErrorLevel, err)
		}

		logger.Log(logging.InfoLevel, "Goodbye!")
	},
}

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