Skip to content

Commit

Permalink
Fix golint issues
Browse files Browse the repository at this point in the history
Document some internal structs, delete unused ones and fix method names
  • Loading branch information
nlopes committed Aug 23, 2015
1 parent 1f061db commit 32464d1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rtm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (api *Client) StartRTM() (info *Info, websocketURL string, err error) {
// Fixed by: https://github.com/golang/net/commit/5058c78c3627b31e484a81463acd51c7cecc06f3
// but slack returns the address with no port, so we have to fix it
api.Debugln("Using URL:", response.Info.URL)
websocketURL, err = websocketizeUrlPort(response.Info.URL)
websocketURL, err = websocketizeURLPort(response.Info.URL)
if err != nil {
return nil, "", fmt.Errorf("parsing response URL: %s", err)
}
Expand Down
20 changes: 12 additions & 8 deletions websocket_internals.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
/**
* Internal events, created by this lib and not mapped to Slack APIs.
*/

// ConnectedEvent is used for when we connect to Slack
type ConnectedEvent struct {
ConnectionCount int // 1 = first time, 2 = second time
Info *Info
}

// ConnectionErrorEvent contains information about a connection error
type ConnectionErrorEvent struct {
Attempt int
ErrorObj error
Expand All @@ -22,21 +25,26 @@ func (c *ConnectionErrorEvent) Error() string {
return c.ErrorObj.Error()
}

// ConnectingEvent contains information about our connection attempt
type ConnectingEvent struct {
Attempt int // 1 = first attempt, 2 = second attempt
ConnectionCount int
}

// DisconnectedEvent contains information about how we disconnected
type DisconnectedEvent struct {
Intentional bool
}

// LatencyReport contains information about connection latency
type LatencyReport struct {
Value time.Duration
}

// InvalidAuthEvent is used in case we can't even authenticate with the API
type InvalidAuthEvent struct{}

// UnmarshallingErrorEvent is used when there are issues deconstructing a response
type UnmarshallingErrorEvent struct {
ErrorObj error
}
Expand All @@ -45,6 +53,7 @@ func (u UnmarshallingErrorEvent) Error() string {
return u.ErrorObj.Error()
}

// MessageTooLongEvent is used when sending a message that is too long
type MessageTooLongEvent struct {
Message OutgoingMessage
MaxLength int
Expand All @@ -54,6 +63,7 @@ func (m *MessageTooLongEvent) Error() string {
return fmt.Sprintf("Message too long (max %d characters)", m.MaxLength)
}

// OutgoingErrorEvent contains information in case there were errors sending messages
type OutgoingErrorEvent struct {
Message OutgoingMessage
ErrorObj error
Expand All @@ -63,6 +73,7 @@ func (o OutgoingErrorEvent) Error() string {
return o.ErrorObj.Error()
}

// IncomingEventError contains information about an unexpected error receiving a websocket event
type IncomingEventError struct {
ErrorObj error
}
Expand All @@ -71,18 +82,11 @@ func (i *IncomingEventError) Error() string {
return i.ErrorObj.Error()
}

// AckErrorEvent i
type AckErrorEvent struct {
ErrorObj error
}

func (a *AckErrorEvent) Error() string {
return a.ErrorObj.Error()
}

type SlackErrorEvent struct {
ErrorObj error
}

func (s SlackErrorEvent) Error() string {
return s.ErrorObj.Error()
}
4 changes: 4 additions & 0 deletions websocket_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ type AckMessage struct {
RTMResponse
}

// RTMResponse encapsulates response details as returned by the Slack API
type RTMResponse struct {
Ok bool `json:"ok"`
Error *RTMError `json:"error"`
}

// RTMError encapsulates error information as returned by the Slack API
type RTMError struct {
Code int
Msg string
Expand All @@ -27,6 +29,7 @@ func (s RTMError) Error() string {
return fmt.Sprintf("Code %d - %s", s.Code, s.Msg)
}

// MessageEvent represents a Slack Message (used as the event type for an incoming message)
type MessageEvent Message

// RTMEvent is the main wrapper. You will find all the other messages attached
Expand All @@ -52,6 +55,7 @@ type UserTypingEvent struct {
Channel string `json:"channel"`
}

// PrefChangeEvent represents a user preferences change event
type PrefChangeEvent struct {
Type string `json:"type"`
Name string `json:"name"`
Expand Down
3 changes: 2 additions & 1 deletion websocket_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"
)

// JSONTimeString is an auxiliary type to allow us to format the time as we wish
type JSONTimeString string

// String converts the unix timestamp into a string
Expand All @@ -28,7 +29,7 @@ func (t JSONTimeString) String() string {

var portMapping = map[string]string{"ws": "80", "wss": "443"}

func websocketizeUrlPort(orig string) (string, error) {
func websocketizeURLPort(orig string) (string, error) {
urlObj, err := url.ParseRequestURI(orig)
if err != nil {
return "", err
Expand Down

0 comments on commit 32464d1

Please sign in to comment.