From ba3b69951710af59e0399fd0a0244f1eb1568953 Mon Sep 17 00:00:00 2001 From: Jonhnny Weslley Date: Sun, 24 Jan 2016 11:54:06 -0300 Subject: [PATCH 1/2] refactor common logic --- ipe/channel.go | 5 +++-- ipe/websockets.go | 4 ++-- utils/utils.go | 9 +++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ipe/channel.go b/ipe/channel.go index 2dc9cf8..3ed2aff 100644 --- a/ipe/channel.go +++ b/ipe/channel.go @@ -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 diff --git a/ipe/websockets.go b/ipe/websockets.go index 1e9e0e8..1106ca7 100644 --- a/ipe/websockets.go +++ b/ipe/websockets.go @@ -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} diff --git a/utils/utils.go b/utils/utils.go index af6748f..51b4ce2 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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-") +} From 8bf0786cb5e52c511eb2280984f110a22d63c685 Mon Sep 17 00:00:00 2001 From: Jonhnny Weslley Date: Sun, 24 Jan 2016 12:04:31 -0300 Subject: [PATCH 2/2] add systemd config file --- init/systemd/ipe.service | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 init/systemd/ipe.service diff --git a/init/systemd/ipe.service b/init/systemd/ipe.service new file mode 100644 index 0000000..4a89067 --- /dev/null +++ b/init/systemd/ipe.service @@ -0,0 +1,14 @@ +[Unit] +Description=Ipe +After=syslog.target network.target + +[Service] +Type=simple +User=ipe +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=ipe +ExecStart=/path/to/ipe -logtostderr -config="path_to_config.json" + +[Install] +WantedBy=multi-user.target