From 97da70dfb735df0ebb83fa36e1651a60fd8fc96b Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Sat, 10 Oct 2015 23:08:23 +0200 Subject: [PATCH] Fix panic when running on older GoTTY server (#13) --- README.md | 1 + gotty-client.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f3b195c..830f395a 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Mon Aug 24 18:54:38 CEST 2015 ### master (unreleased) +* Fix panic when running on older GoTTY server ([#13](https://github.com/moul/gotty-client/issues/13)) * Add 'homebrew support' ([#1](https://github.com/moul/gotty-client/issues/1)) * Add Changelog ([#5](https://github.com/moul/gotty-client/issues/5)) * Add GOXC configuration to build binaries for multiple architectures ([#2](https://github.com/moul/gotty-client/issues/2)) diff --git a/gotty-client.go b/gotty-client.go index 3695ab06..33e24c85 100644 --- a/gotty-client.go +++ b/gotty-client.go @@ -111,7 +111,12 @@ func (c *Client) GetAuthToken() (string, error) { } re := regexp.MustCompile("var gotty_auth_token = '(.*)'") - return re.FindStringSubmatch(string(body))[1], nil + output := re.FindStringSubmatch(string(body)) + if len(output) == 0 { + return "", fmt.Errorf("Cannot fetch GoTTY auth-token, please upgrade your GoTTY server.") + } + + return output[1], nil } // Connect tries to dial a websocket server