refactor common logic

This commit is contained in:
Jonhnny Weslley
2016-01-24 11:54:06 -03:00
parent 517462a7af
commit ba3b699517
3 changed files with 14 additions and 4 deletions
+3 -2
View File
@@ -11,6 +11,7 @@ import (
"sync"
"time"
"github.com/dimiro1/ipe/utils"
log "github.com/golang/glog"
)
@@ -40,12 +41,12 @@ func (c *channel) IsPublic() bool {
// Check if the type of the channel is presence
func (c *channel) IsPresence() bool {
return strings.HasPrefix(c.ChannelID, "presence-")
return utils.IsPresenceChannel(c.ChannelID)
}
// Check if the type of the channel is private
func (c *channel) IsPrivate() bool {
return strings.HasPrefix(c.ChannelID, "private-")
return utils.IsPrivateChannel(c.ChannelID)
}
// Get the total of subscribers
+2 -2
View File
@@ -123,8 +123,8 @@ func onMessage(conn *websocket.Conn, w http.ResponseWriter, r *http.Request, ses
break
}
isPresence := strings.HasPrefix(channelName, "presence-")
isPrivate := strings.HasPrefix(channelName, "private-")
isPresence := utils.IsPresenceChannel(channelName)
isPrivate := utils.IsPrivateChannel(channelName)
if isPresence || isPrivate {
toSign := []string{connection.SocketID, channelName}
+9
View File
@@ -12,6 +12,7 @@ import (
"math"
"math/rand"
"regexp"
"strings"
)
var validChannelName *regexp.Regexp
@@ -38,3 +39,11 @@ func GenerateSessionID() string {
func IsChannelNameValid(channelName string) bool {
return validChannelName.Match([]byte(channelName))
}
func IsPrivateChannel(channelName string) bool {
return strings.HasPrefix(channelName, "private-")
}
func IsPresenceChannel(channelName string) bool {
return strings.HasPrefix(channelName, "presence-")
}