From 51992ac94f71e2b9ccb712618ad531ccf9d894ab Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Sun, 22 Dec 2019 08:47:37 +0000 Subject: [PATCH] Allow for incorrect and missing schemes. Fixes #12 Also picked up a few unrelated gofmt changes. Signed-off-by: Brian Brazil --- connection.go | 2 +- main.go | 18 +++++++++++++++++- .../mattn/go-colorable/colorable_windows.go | 6 +++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/connection.go b/connection.go index 9a6265e..55fa90b 100644 --- a/connection.go +++ b/connection.go @@ -24,7 +24,7 @@ func connect(url, origin string, rlConf *readline.Config, allowInsecure bool) er dialer := websocket.Dialer{ Proxy: http.ProxyFromEnvironment, - TLSClientConfig:&tls.Config{ + TLSClientConfig: &tls.Config{ InsecureSkipVerify: allowInsecure, }, } diff --git a/main.go b/main.go index 7fdc26b..8847ad1 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ const Version = "0.2.1" var options struct { origin string printVersion bool - insecure bool + insecure bool } func main() { @@ -50,6 +50,22 @@ func root(cmd *cobra.Command, args []string) { os.Exit(1) } + // Correct and add missing schemes. + switch dest.Scheme { + case "ws", "wss": + case "http": + dest.Scheme = "ws" + case "https": + dest.Scheme = "wss" + default: + // Likely no scheme at all, e.g. "localhost:8000". + dest, err = url.Parse("ws://" + args[0]) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + } + var origin string if options.origin != "" { origin = options.origin diff --git a/vendor/github.com/mattn/go-colorable/colorable_windows.go b/vendor/github.com/mattn/go-colorable/colorable_windows.go index 22f075f..d52bccf 100644 --- a/vendor/github.com/mattn/go-colorable/colorable_windows.go +++ b/vendor/github.com/mattn/go-colorable/colorable_windows.go @@ -466,7 +466,7 @@ loop: continue } procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) - csbi.cursorPosition.x = short(n-1) + csbi.cursorPosition.x = short(n - 1) procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) case 'H': token := strings.Split(buf.String(), ";") @@ -481,8 +481,8 @@ loop: if err != nil { continue } - csbi.cursorPosition.x = short(n2-1) - csbi.cursorPosition.y = short(n1-1) + csbi.cursorPosition.x = short(n2 - 1) + csbi.cursorPosition.y = short(n1 - 1) procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) case 'J': n, err := strconv.Atoi(buf.String())