From 3fc072373a35a806bfa11e960facfa490bb6f554 Mon Sep 17 00:00:00 2001 From: claudemiro Date: Sat, 16 Jan 2016 21:20:23 -0200 Subject: [PATCH] Fix lint suggestions --- ipe/channel.go | 4 ++-- ipe/events.go | 12 ++++++------ ipe/rest.go | 4 ++-- ipe/router.go | 1 - ipe/routes.go | 10 +++++----- ipe/subscription.go | 2 +- ipe/webhooks.go | 12 ++++++------ main.go | 2 +- utils/utils.go | 3 ++- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ipe/channel.go b/ipe/channel.go index 0309da9..2dc9cf8 100644 --- a/ipe/channel.go +++ b/ipe/channel.go @@ -58,7 +58,7 @@ func (c *channel) TotalUsers() int { total := make(map[string]int) for _, s := range c.Subscriptions { - total[s.Id]++ + total[s.ID]++ } return len(total) @@ -96,7 +96,7 @@ func (c *channel) Subscribe(a *app, conn *connection, channelData string) error } // Update the Subscription - subscription.Id = info.UserID + subscription.ID = info.UserID subscription.Data = string(js) // Publish pusher_internal:member_added diff --git a/ipe/events.go b/ipe/events.go index 5148820..32edebf 100644 --- a/ipe/events.go +++ b/ipe/events.go @@ -106,8 +106,8 @@ func newSubscriptionSucceedEventPresenceData(c *channel) subscriptionSucceeedEve var js interface{} json.Unmarshal([]byte(s.Data), &js) - hash[s.Id] = js - ids = append(ids, s.Id) + hash[s.ID] = js + ids = append(ids, s.ID) } event.Ids = ids @@ -193,7 +193,7 @@ func newErrorEvent(code int, message string) errorEvent { // } // } type connectionEstablishedEventData struct { - SocketId string `json:"socket_id"` + SocketID string `json:"socket_id"` ActivityTimeout int `json:"activity_timeout"` } @@ -203,8 +203,8 @@ type connectionEstablishedEvent struct { } // Create a new connection established event using the specified socketId -func newConnectionEstablishedEvent(socketId string) connectionEstablishedEvent { - data := connectionEstablishedEventData{SocketId: socketId, ActivityTimeout: 120} +func newConnectionEstablishedEvent(socketID string) connectionEstablishedEvent { + data := connectionEstablishedEventData{SocketID: socketID, ActivityTimeout: 120} b, err := json.Marshal(data) @@ -245,7 +245,7 @@ func newMemberRemovedEvent(channel string, s *subscription) memberRemovedEvent { data, err := json.Marshal(struct { UserID string `json:"user_id"` }{ - UserID: s.Id, + UserID: s.ID, }) if err != nil { diff --git a/ipe/rest.go b/ipe/rest.go index 80f59e3..ac4d83c 100644 --- a/ipe/rest.go +++ b/ipe/rest.go @@ -300,8 +300,8 @@ func getChannelUsers(w http.ResponseWriter, r *http.Request) { for _, s := range channel.Subscriptions { users = append(users, struct { - Id string `json:"id"` - }{s.Id}) + ID string `json:"id"` + }{s.ID}) } result["users"] = users diff --git a/ipe/router.go b/ipe/router.go index 42f387a..dc0b8ab 100644 --- a/ipe/router.go +++ b/ipe/router.go @@ -5,7 +5,6 @@ package ipe import ( - _ "expvar" "net/http" "github.com/gorilla/mux" diff --git a/ipe/routes.go b/ipe/routes.go index 5662eb4..e1cbbf5 100644 --- a/ipe/routes.go +++ b/ipe/routes.go @@ -18,35 +18,35 @@ type route struct { } var routes = []route{ - route{ + { "PostEvents", "POST", "/apps/{app_id}/events", postEvents, true, }, - route{ + { "GetChannels", "GET", "/apps/{app_id}/channels", getChannels, true, }, - route{ + { "GetChannel", "GET", "/apps/{app_id}/channels/{channel_name}", getChannel, true, }, - route{ + { "GetChannelUsers", "GET", "/apps/{app_id}/channels/{channel_name}/users", getChannelUsers, true, }, - route{ + { "Websocket", "GET", "/app/{key}", diff --git a/ipe/subscription.go b/ipe/subscription.go index 21dca0f..45d12f3 100644 --- a/ipe/subscription.go +++ b/ipe/subscription.go @@ -7,7 +7,7 @@ package ipe // A Channel Subscription type subscription struct { Connection *connection - Id string + ID string Data string } diff --git a/ipe/webhooks.go b/ipe/webhooks.go index 9cf4fc5..0503848 100644 --- a/ipe/webhooks.go +++ b/ipe/webhooks.go @@ -44,7 +44,7 @@ type hookEvent struct { Event string `json:"event,omitempty"` Data interface{} `json:"data,omitempty"` SocketID string `json:"socket_id,omitempty"` - UserId string `json:"user_id,omitempty"` + UserID string `json:"user_id,omitempty"` } func newChannelOcuppiedHook(channel *channel) hookEvent { @@ -56,11 +56,11 @@ func newChannelVacatedHook(channel *channel) hookEvent { } func newMemberAddedHook(channel *channel, s *subscription) hookEvent { - return hookEvent{Name: "member_added", Channel: channel.ChannelID, UserId: s.Id} + return hookEvent{Name: "member_added", Channel: channel.ChannelID, UserID: s.ID} } func newMemberRemovedHook(channel *channel, s *subscription) hookEvent { - return hookEvent{Name: "member_removed", Channel: channel.ChannelID, UserId: s.Id} + return hookEvent{Name: "member_removed", Channel: channel.ChannelID, UserID: s.ID} } func newClientHook(channel *channel, s *subscription, event string, data interface{}) hookEvent { @@ -89,11 +89,11 @@ func (a *app) TriggerChannelVacatedHook(c *channel) { // "socket_id": "socket_id of the sending socket", // "user_id": "user_id associated with the sending socket" # Only for presence channels // } -func (a *app) TriggerClientEventHook(c *channel, s *subscription, client_event string, data interface{}) { - event := newClientHook(c, s, client_event, data) +func (a *app) TriggerClientEventHook(c *channel, s *subscription, clientEvent string, data interface{}) { + event := newClientHook(c, s, clientEvent, data) if c.IsPresence() { - event.UserId = s.Id + event.UserID = s.ID } triggerHook(event.Name, a, c, event) diff --git a/main.go b/main.go index 0fc872b..9e16226 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ func main() { } } -// Print a beatifull banner +// Print a beautifull banner func printBanner() { fmt.Print("\033[36m") fmt.Print(` diff --git a/utils/utils.go b/utils/utils.go index c628900..7b7ab9c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -23,7 +23,7 @@ func HashMAC(message, key []byte) string { return hex.EncodeToString(expected) } -// Generate a new random Hash +// GenerateSessionID Generate a new random Hash func GenerateSessionID() string { MAX := 999999999 rand.Seed(time.Now().Unix()) @@ -31,6 +31,7 @@ func GenerateSessionID() string { return fmt.Sprintf("%d.%d", rand.Intn(MAX), rand.Intn(MAX)) } +// IsChannelNameValid Verify if the channel name is valid func IsChannelNameValid(channelName string) bool { matched, err := regexp.MatchString("^[A-Za-z0-9_\\-=@,.;]+$", channelName)