summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2023-07-15 16:58:36 -0700
committerMike Crute <mike@crute.us>2023-07-15 16:58:36 -0700
commitfea07831eadd35532055ec16fc43b0cde56a54b1 (patch)
tree35c304a16e5b6f9acadb9c66f4c48215ad9abd2b /main.go
parent51949f8dc563c7c1ce03d8862abbee4cc1e20943 (diff)
downloadwebsocket_proxy-fea07831eadd35532055ec16fc43b0cde56a54b1.tar.bz2
websocket_proxy-fea07831eadd35532055ec16fc43b0cde56a54b1.tar.xz
websocket_proxy-fea07831eadd35532055ec16fc43b0cde56a54b1.zip
Cleanup, add local client
Diffstat (limited to 'main.go')
-rw-r--r--main.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/main.go b/main.go
index 00fe063..1ac3351 100644
--- a/main.go
+++ b/main.go
@@ -50,6 +50,32 @@ var clientCmd = &cobra.Command{
50 }, 50 },
51} 51}
52 52
53var localClientCmd = &cobra.Command{
54 Use: "localclient [server host]",
55 Short: "Act as a client for a websocket-proxy server",
56 Args: func(cmd *cobra.Command, args []string) error {
57 if len(args) != 1 || args[0] == "" {
58 return errors.New("Server host is a required argument")
59 }
60 if !strings.HasPrefix(args[0], "ws://") && !strings.HasPrefix(args[0], "wss://") {
61 return errors.New("Server host format is ws[s]://host[:port]/[path]")
62 }
63 return nil
64 },
65 Run: func(cmd *cobra.Command, args []string) {
66 // TODO: Handle signals
67 ctx, cancel := context.WithCancel(context.Background())
68 defer cancel()
69
70 h := &LocalClientHandler{
71 WebsocketServer: args[0],
72 Context: ctx,
73 }
74
75 h.Run()
76 },
77}
78
53var serverCmd = &cobra.Command{ 79var serverCmd = &cobra.Command{
54 Use: "server [next-hop host]", 80 Use: "server [next-hop host]",
55 Short: "Serve websocket proxy client", 81 Short: "Serve websocket proxy client",
@@ -69,7 +95,10 @@ var serverCmd = &cobra.Command{
69} 95}
70 96
71func main() { 97func main() {
98 log.SetOutput(os.Stderr)
99
72 rootCmd.AddCommand(clientCmd) 100 rootCmd.AddCommand(clientCmd)
101 rootCmd.AddCommand(localClientCmd)
73 rootCmd.AddCommand(serverCmd) 102 rootCmd.AddCommand(serverCmd)
74 103
75 clientCmd.Flags().StringP("listen", "l", ":9013", "[address]:port to bind for serving clients") 104 clientCmd.Flags().StringP("listen", "l", ":9013", "[address]:port to bind for serving clients")