Fixed typos, linter warnings

This commit is contained in:
Roman Nikitin 2020-09-22 12:32:23 +03:00
parent d786e7669f
commit f8268d4ac0
1 changed files with 19 additions and 19 deletions

View File

@ -89,8 +89,8 @@ func GetAuthTokenURL(httpURL string) (*url.URL, *http.Header, error) {
} }
// GetURLQuery returns url.query // GetURLQuery returns url.query
func GetURLQuery(rawurl string) (url.Values, error) { func GetURLQuery(rawURL string) (url.Values, error) {
target, err := url.Parse(rawurl) target, err := url.Parse(rawURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -191,7 +191,7 @@ func (c *Client) GetAuthToken() (string, error) {
re := regexp.MustCompile("var gotty_auth_token = '(.*)'") re := regexp.MustCompile("var gotty_auth_token = '(.*)'")
output := re.FindStringSubmatch(string(body)) output := re.FindStringSubmatch(string(body))
if len(output) == 0 { if len(output) == 0 {
return "", fmt.Errorf("Cannot fetch GoTTY auth-token, please upgrade your GoTTY server.") return "", fmt.Errorf("cannot fetch GoTTY auth-token, please upgrade your GoTTY server")
} }
return output[1], nil return output[1], nil
@ -237,14 +237,14 @@ func (c *Client) Connect() error {
Arguments: "?" + query.Encode(), Arguments: "?" + query.Encode(),
AuthToken: authToken, AuthToken: authToken,
} }
json, err := json.Marshal(querySingle) queryJson, err := json.Marshal(querySingle)
if err != nil { if err != nil {
logrus.Errorf("Failed to parse init message %v", err) logrus.Errorf("Failed to parse init message %v", err)
return err return err
} }
// Send Json // Send Json
logrus.Debugf("Sending arguments and auth-token") logrus.Debugf("Sending arguments and auth-token")
err = c.write(json) err = c.write(queryJson)
if err != nil { if err != nil {
return err return err
} }
@ -296,8 +296,8 @@ func (c *Client) pingLoop() {
} }
// Close will nicely close the dialer // Close will nicely close the dialer
func (c *Client) Close() { func (c *Client) Close() error {
c.Conn.Close() return c.Conn.Close()
} }
// ExitLoop will kill all goroutines launched by c.Loop() // ExitLoop will kill all goroutines launched by c.Loop()
@ -322,7 +322,7 @@ func (c *Client) Loop() error {
} }
err = term.SetRaw() err = term.SetRaw()
if err != nil { if err != nil {
return fmt.Errorf("Error setting raw terminal: %v", err) return fmt.Errorf("error setting raw terminal: %v", err)
} }
defer func() { defer func() {
_ = term.Reset() _ = term.Reset()
@ -351,14 +351,14 @@ type winsize struct {
Columns uint16 `json:"columns"` Columns uint16 `json:"columns"`
} }
type posionReason int type poisonReason int
const ( const (
committedSuicide = iota committedSuicide = iota
killed killed
) )
func openPoison(fname string, poison chan bool) posionReason { func openPoison(fname string, poison chan bool) poisonReason {
logrus.Debug(fname + " suicide") logrus.Debug(fname + " suicide")
/* /*
@ -376,18 +376,18 @@ func openPoison(fname string, poison chan bool) posionReason {
return committedSuicide return committedSuicide
} }
func die(fname string, poison chan bool) posionReason { func die(fname string, poison chan bool) poisonReason {
logrus.Debug(fname + " died") logrus.Debug(fname + " died")
wasOpen := <-poison wasOpen := <-poison
if wasOpen { if wasOpen {
logrus.Error("ERROR: The channel was open when it wasn't suppoed to be") logrus.Error("ERROR: The channel was open when it wasn't supposed to be")
} }
return killed return killed
} }
func (c *Client) termsizeLoop(wg *sync.WaitGroup) posionReason { func (c *Client) termsizeLoop(wg *sync.WaitGroup) poisonReason {
defer wg.Done() defer wg.Done()
fname := "termsizeLoop" fname := "termsizeLoop"
@ -416,7 +416,7 @@ type exposeFd interface {
Fd() uintptr Fd() uintptr
} }
func (c *Client) writeLoop(wg *sync.WaitGroup) posionReason { func (c *Client) writeLoop(wg *sync.WaitGroup) poisonReason {
defer wg.Done() defer wg.Done()
fname := "writeLoop" fname := "writeLoop"
@ -476,7 +476,7 @@ func (c *Client) writeLoop(wg *sync.WaitGroup) posionReason {
} }
func (c *Client) readLoop(wg *sync.WaitGroup) posionReason { func (c *Client) readLoop(wg *sync.WaitGroup) poisonReason {
defer wg.Done() defer wg.Done()
fname := "readLoop" fname := "readLoop"
@ -506,7 +506,7 @@ func (c *Client) readLoop(wg *sync.WaitGroup) posionReason {
} }
if len(msg.Data) == 0 { if len(msg.Data) == 0 {
logrus.Warnf("An error has occured") logrus.Warnf("An error has occurred")
return openPoison(fname, c.poison) return openPoison(fname, c.poison)
} }
switch msg.Data[0] { switch msg.Data[0] {
@ -520,7 +520,7 @@ func (c *Client) readLoop(wg *sync.WaitGroup) posionReason {
case c.message.pong: // pong case c.message.pong: // pong
case c.message.setWindowTitle: // new title case c.message.setWindowTitle: // new title
newTitle := string(msg.Data[1:]) newTitle := string(msg.Data[1:])
fmt.Fprintf(c.Output, "\033]0;%s\007", newTitle) _, _ = fmt.Fprintf(c.Output, "\033]0;%s\007", newTitle)
case c.message.setPreferences: // json prefs case c.message.setPreferences: // json prefs
logrus.Debugf("Unhandled protocol message: json pref: %s", string(msg.Data[1:])) logrus.Debugf("Unhandled protocol message: json pref: %s", string(msg.Data[1:]))
case c.message.setReconnect: // autoreconnect case c.message.setReconnect: // autoreconnect
@ -554,13 +554,13 @@ func ParseURL(input string) (string, error) {
// NewClient returns a GoTTY client object // NewClient returns a GoTTY client object
func NewClient(inputURL string) (*Client, error) { func NewClient(inputURL string) (*Client, error) {
url, err := ParseURL(inputURL) parsedURL, err := ParseURL(inputURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Client{ return &Client{
Dialer: &websocket.Dialer{}, Dialer: &websocket.Dialer{},
URL: url, URL: parsedURL,
WriteMutex: &sync.Mutex{}, WriteMutex: &sync.Mutex{},
Output: os.Stdout, Output: os.Stdout,
poison: make(chan bool), poison: make(chan bool),