Renamed constants, avoid export uncessary constants

This commit is contained in:
claudemiro
2016-03-04 08:33:18 -03:00
parent e02773bbeb
commit 44bbc1b1ea
5 changed files with 29 additions and 28 deletions
+16 -16
View File
@@ -9,39 +9,39 @@ const (
// 4000 - 4099
// Indicates an error resulting in the connection being closed by Pusher,
// and that attempting to reconnect using the same parameters will not succeed.
APPLICATION_ONLY_ACCEPTS_SSL = 4000
APPLICATION_DOES_NOT_EXISTS = 4001
APPLICATION_DISABLED = 4003
APPLICATION_IS_OVER_CONNECTION_QUOTA = 4004 // Not Implemented
PATH_NOT_FOUND = 4005 // Not Implemented
INVALID_VERSION_STRING_FORMAT = 4006
UNSUPPORTED_PROTOCOL_VERSION = 4007
NO_PROTOCOL_VERSION_SUPPLIED = 4008
applicationOnlyAcceptsSSL = 4000
applicationDoesNotExists = 4001
applicationDisabled = 4003
applicationIsOverConnectionQuota = 4004 // Not Implemented
pathNotFound = 4005 // Not Implemented
invalidVersionStringFormat = 4006
unsupportedProtocolVersion = 4007
noProtocolVersionSupplied = 4008
// 4100 - 4199
// Indicates an error resulting in the connection being closed by Pusher,
// and the client may reconnect after 1s or more
OVER_CAPACITY = 4100 // Not Implemented
overCapacity = 4100 // Not Implemented
// 4200 - 4299
// Indicate an error resulting in the connection being closed by Pusher,
// and the client my reconnect immediately
GENERIC_RECONNECT_IMMEDIATELY = 4200
PONG_REPLY_NOT_RECEIVED = 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
genericReconnectImmediately = 4200
pongReplyNotReceived = 4201 // Ping was sent to the client, but no reply was received; Not Implemented
closedAfterInactivity = 4202 // Client has been inactive for a long time (24 hours) and client does not suppot ping.; Not Implemented
// 4300 - 4399
// 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
// see ErrorEvent
GENERIC_ERROR = 0
otherError = 0
)
// Only this version is supported
const SUPPORTED_PROTOCOL_VERSION = 7
const supportedProtocolVersion = 7
// // Maximun event size permitted 10 kB
// 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
View File
@@ -31,7 +31,7 @@ type unsupportedProtocolVersionError struct {
func newUnsupportedProtocolVersionError() 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 {
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 {
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 {
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 {
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 {
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 {
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 {
return genericError{
baseWebsocketError{Code: GENERIC_ERROR, Msg: msg},
baseWebsocketError{Code: otherError, Msg: msg},
}
}
+1 -1
View File
@@ -164,7 +164,7 @@ type errorEvent struct {
func newErrorEvent(code int, message string) errorEvent {
var data interface{}
if code == GENERIC_ERROR {
if code == otherError {
data = struct {
Code *int `json:"code"`
Message string `json:"message"`
+3 -2
View File
@@ -10,6 +10,7 @@ import (
"net/http"
"strings"
"github.com/dimiro1/ipe/utils"
log "github.com/golang/glog"
"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.
if len(input.Data) > MAX_DATA_EVENT_SIZE {
if len(input.Data) > maxDataEventSize {
http.Error(w, "Request too large.", http.StatusRequestEntityTooLarge)
return
}
@@ -272,7 +273,7 @@ func getChannelUsers(w http.ResponseWriter, r *http.Request) {
appID := vars["app_id"]
channelName := vars["channel_name"]
isPresence := strings.HasPrefix(channelName, "presence-")
isPresence := utils.IsPresenceChannel(channelName)
if !isPresence {
http.Error(w, "This api endpoint is restricted to presence channels.", http.StatusBadRequest)
+1 -1
View File
@@ -39,7 +39,7 @@ func onOpen(conn *websocket.Conn, w http.ResponseWriter, r *http.Request, sessio
switch {
case strings.TrimSpace(p) == "":
return newNoProtocolVersionSuppliedError()
case protocol != SUPPORTED_PROTOCOL_VERSION:
case protocol != supportedProtocolVersion:
return newUnsupportedProtocolVersionError()
case app.ApplicationDisabled:
return newApplicationDisabledError()