Renamed constants, avoid export uncessary constants
This commit is contained in:
+16
-16
@@ -9,39 +9,39 @@ const (
|
|||||||
// 4000 - 4099
|
// 4000 - 4099
|
||||||
// Indicates an error resulting in the connection being closed by Pusher,
|
// Indicates an error resulting in the connection being closed by Pusher,
|
||||||
// and that attempting to reconnect using the same parameters will not succeed.
|
// and that attempting to reconnect using the same parameters will not succeed.
|
||||||
APPLICATION_ONLY_ACCEPTS_SSL = 4000
|
applicationOnlyAcceptsSSL = 4000
|
||||||
APPLICATION_DOES_NOT_EXISTS = 4001
|
applicationDoesNotExists = 4001
|
||||||
APPLICATION_DISABLED = 4003
|
applicationDisabled = 4003
|
||||||
APPLICATION_IS_OVER_CONNECTION_QUOTA = 4004 // Not Implemented
|
applicationIsOverConnectionQuota = 4004 // Not Implemented
|
||||||
PATH_NOT_FOUND = 4005 // Not Implemented
|
pathNotFound = 4005 // Not Implemented
|
||||||
INVALID_VERSION_STRING_FORMAT = 4006
|
invalidVersionStringFormat = 4006
|
||||||
UNSUPPORTED_PROTOCOL_VERSION = 4007
|
unsupportedProtocolVersion = 4007
|
||||||
NO_PROTOCOL_VERSION_SUPPLIED = 4008
|
noProtocolVersionSupplied = 4008
|
||||||
|
|
||||||
// 4100 - 4199
|
// 4100 - 4199
|
||||||
// Indicates an error resulting in the connection being closed by Pusher,
|
// Indicates an error resulting in the connection being closed by Pusher,
|
||||||
// and the client may reconnect after 1s or more
|
// and the client may reconnect after 1s or more
|
||||||
OVER_CAPACITY = 4100 // Not Implemented
|
overCapacity = 4100 // Not Implemented
|
||||||
|
|
||||||
// 4200 - 4299
|
// 4200 - 4299
|
||||||
// Indicate an error resulting in the connection being closed by Pusher,
|
// Indicate an error resulting in the connection being closed by Pusher,
|
||||||
// and the client my reconnect immediately
|
// and the client my reconnect immediately
|
||||||
GENERIC_RECONNECT_IMMEDIATELY = 4200
|
genericReconnectImmediately = 4200
|
||||||
PONG_REPLY_NOT_RECEIVED = 4201 // Ping was sent to the client, but no reply was received; Not Implemented
|
pongReplyNotReceived = 4201 // Ping was sent to the client, but no reply was received; Not Implemented
|
||||||
CLOSED_AFTER_INACTIVITY = 4202 // Client has been inactive for a long time (24 hours) and client does not suppot ping.; Not Implemented
|
closedAfterInactivity = 4202 // Client has been inactive for a long time (24 hours) and client does not suppot ping.; Not Implemented
|
||||||
|
|
||||||
// 4300 - 4399
|
// 4300 - 4399
|
||||||
// Any other type of error
|
// Any other type of error
|
||||||
CLIENT_REJECTED_DUE_TO_RATE_LIMIT = 4301 // Not Implemented
|
clientRejectedDueToRateLimit = 4301 // Not Implemented
|
||||||
|
|
||||||
// Pusher send null, This app use this error code to send the null value
|
// Pusher send null, This app use this error code to send the null value
|
||||||
// see ErrorEvent
|
// see ErrorEvent
|
||||||
GENERIC_ERROR = 0
|
otherError = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
// Only this version is supported
|
// Only this version is supported
|
||||||
const SUPPORTED_PROTOCOL_VERSION = 7
|
const supportedProtocolVersion = 7
|
||||||
|
|
||||||
// // Maximun event size permitted 10 kB
|
// // Maximun event size permitted 10 kB
|
||||||
// See: http://blogs.gnome.org/cneumair/2008/09/30/1-kb-1024-bytes-no-1-kb-1000-bytes/
|
// See: http://blogs.gnome.org/cneumair/2008/09/30/1-kb-1024-bytes-no-1-kb-1000-bytes/
|
||||||
const MAX_DATA_EVENT_SIZE = 10 * 1000
|
const maxDataEventSize = 10 * 1000
|
||||||
|
|||||||
+8
-8
@@ -31,7 +31,7 @@ type unsupportedProtocolVersionError struct {
|
|||||||
|
|
||||||
func newUnsupportedProtocolVersionError() unsupportedProtocolVersionError {
|
func newUnsupportedProtocolVersionError() unsupportedProtocolVersionError {
|
||||||
return unsupportedProtocolVersionError{
|
return unsupportedProtocolVersionError{
|
||||||
baseWebsocketError{Code: UNSUPPORTED_PROTOCOL_VERSION, Msg: "Unsupported protocol version"},
|
baseWebsocketError{Code: unsupportedProtocolVersion, Msg: "Unsupported protocol version"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ type applicationDoesNotExistsError struct {
|
|||||||
|
|
||||||
func newApplicationDoesNotExistsError() applicationDoesNotExistsError {
|
func newApplicationDoesNotExistsError() applicationDoesNotExistsError {
|
||||||
return applicationDoesNotExistsError{
|
return applicationDoesNotExistsError{
|
||||||
baseWebsocketError{Code: APPLICATION_DOES_NOT_EXISTS, Msg: "Could not found an app with the given key"},
|
baseWebsocketError{Code: applicationDoesNotExists, Msg: "Could not found an app with the given key"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ type noProtocolVersionSuppliedError struct {
|
|||||||
|
|
||||||
func newNoProtocolVersionSuppliedError() noProtocolVersionSuppliedError {
|
func newNoProtocolVersionSuppliedError() noProtocolVersionSuppliedError {
|
||||||
return noProtocolVersionSuppliedError{
|
return noProtocolVersionSuppliedError{
|
||||||
baseWebsocketError{Code: NO_PROTOCOL_VERSION_SUPPLIED, Msg: "No protocol version supplied"},
|
baseWebsocketError{Code: noProtocolVersionSupplied, Msg: "No protocol version supplied"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ type applicationDisabledError struct {
|
|||||||
|
|
||||||
func newApplicationDisabledError() noProtocolVersionSuppliedError {
|
func newApplicationDisabledError() noProtocolVersionSuppliedError {
|
||||||
return noProtocolVersionSuppliedError{
|
return noProtocolVersionSuppliedError{
|
||||||
baseWebsocketError{Code: APPLICATION_DISABLED, Msg: "Application disabled"},
|
baseWebsocketError{Code: applicationDisabled, Msg: "Application disabled"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ type applicationOnlyAccepsSSLError struct {
|
|||||||
|
|
||||||
func newApplicationOnlyAccepsSSLError() applicationOnlyAccepsSSLError {
|
func newApplicationOnlyAccepsSSLError() applicationOnlyAccepsSSLError {
|
||||||
return applicationOnlyAccepsSSLError{
|
return applicationOnlyAccepsSSLError{
|
||||||
baseWebsocketError{Code: APPLICATION_ONLY_ACCEPTS_SSL, Msg: "Application only accepts SSL connections, reconnect using wss://"},
|
baseWebsocketError{Code: applicationOnlyAcceptsSSL, Msg: "Application only accepts SSL connections, reconnect using wss://"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ type invalidVersionStringFormatError struct {
|
|||||||
|
|
||||||
func newInvalidVersionStringFormatError() invalidVersionStringFormatError {
|
func newInvalidVersionStringFormatError() invalidVersionStringFormatError {
|
||||||
return invalidVersionStringFormatError{
|
return invalidVersionStringFormatError{
|
||||||
baseWebsocketError{Code: INVALID_VERSION_STRING_FORMAT, Msg: "Invalid version string format"},
|
baseWebsocketError{Code: invalidVersionStringFormat, Msg: "Invalid version string format"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ type genericReconnectImmediatelyError struct {
|
|||||||
|
|
||||||
func newGenericReconnectImmediatelyError() genericReconnectImmediatelyError {
|
func newGenericReconnectImmediatelyError() genericReconnectImmediatelyError {
|
||||||
return genericReconnectImmediatelyError{
|
return genericReconnectImmediatelyError{
|
||||||
baseWebsocketError{Code: GENERIC_RECONNECT_IMMEDIATELY, Msg: "Generic reconnect immediately"},
|
baseWebsocketError{Code: genericReconnectImmediately, Msg: "Generic reconnect immediately"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +113,6 @@ type genericError struct {
|
|||||||
|
|
||||||
func newGenericError(msg string) genericError {
|
func newGenericError(msg string) genericError {
|
||||||
return genericError{
|
return genericError{
|
||||||
baseWebsocketError{Code: GENERIC_ERROR, Msg: msg},
|
baseWebsocketError{Code: otherError, Msg: msg},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -164,7 +164,7 @@ type errorEvent struct {
|
|||||||
func newErrorEvent(code int, message string) errorEvent {
|
func newErrorEvent(code int, message string) errorEvent {
|
||||||
var data interface{}
|
var data interface{}
|
||||||
|
|
||||||
if code == GENERIC_ERROR {
|
if code == otherError {
|
||||||
data = struct {
|
data = struct {
|
||||||
Code *int `json:"code"`
|
Code *int `json:"code"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
|||||||
+3
-2
@@ -10,6 +10,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/dimiro1/ipe/utils"
|
||||||
log "github.com/golang/glog"
|
log "github.com/golang/glog"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
@@ -55,7 +56,7 @@ func postEvents(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The event data should not be larger than 10KB.
|
// The event data should not be larger than 10KB.
|
||||||
if len(input.Data) > MAX_DATA_EVENT_SIZE {
|
if len(input.Data) > maxDataEventSize {
|
||||||
http.Error(w, "Request too large.", http.StatusRequestEntityTooLarge)
|
http.Error(w, "Request too large.", http.StatusRequestEntityTooLarge)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -272,7 +273,7 @@ func getChannelUsers(w http.ResponseWriter, r *http.Request) {
|
|||||||
appID := vars["app_id"]
|
appID := vars["app_id"]
|
||||||
channelName := vars["channel_name"]
|
channelName := vars["channel_name"]
|
||||||
|
|
||||||
isPresence := strings.HasPrefix(channelName, "presence-")
|
isPresence := utils.IsPresenceChannel(channelName)
|
||||||
|
|
||||||
if !isPresence {
|
if !isPresence {
|
||||||
http.Error(w, "This api endpoint is restricted to presence channels.", http.StatusBadRequest)
|
http.Error(w, "This api endpoint is restricted to presence channels.", http.StatusBadRequest)
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ func onOpen(conn *websocket.Conn, w http.ResponseWriter, r *http.Request, sessio
|
|||||||
switch {
|
switch {
|
||||||
case strings.TrimSpace(p) == "":
|
case strings.TrimSpace(p) == "":
|
||||||
return newNoProtocolVersionSuppliedError()
|
return newNoProtocolVersionSuppliedError()
|
||||||
case protocol != SUPPORTED_PROTOCOL_VERSION:
|
case protocol != supportedProtocolVersion:
|
||||||
return newUnsupportedProtocolVersionError()
|
return newUnsupportedProtocolVersionError()
|
||||||
case app.ApplicationDisabled:
|
case app.ApplicationDisabled:
|
||||||
return newApplicationDisabledError()
|
return newApplicationDisabledError()
|
||||||
|
|||||||
Reference in New Issue
Block a user