Documentation
¶
Overview ¶
Package app is a package that contains the core functionality of the GoCore framework and websocket functionality
Index ¶
- Variables
- func BroadcastWebSocketData(data []byte)
- func BroadcastWebSocketJSON(v interface{})
- func CloseAllSockets()
- func GetAllWebSocketMeta() (items *sync.Map)
- func Init()
- func InitCustomWebConfig(webConfig string)
- func Initialize(path string, config string)
- func InitializeLite(secureHeaders bool, allowedHosts []string) (err error)
- func PublishWebSocketJSON(key string, v interface{})
- func RegisterWebSocketDataCallback(callback WebSocketCallback)
- func RemoveWebSocketMeta(id string)
- func ReplyToWebSocket(conn *WebSocketConnection, data []byte)
- func ReplyToWebSocketJSON(conn *WebSocketConnection, v interface{})
- func ReplyToWebSocketPubSub(conn *WebSocketConnection, key string, v interface{})
- func Run()
- func RunLite(port int)
- func RunServer()
- func SetWebSocketMeta(id string, info *WebSocketConnectionMeta)
- func SetWebSocketTimeout(timeout int)
- type ConcurrentWebSocketCallbackItem
- type ConcurrentWebSocketConnectionItem
- type GinContextSync
- type WebSocketCallback
- type WebSocketCallbackSync
- type WebSocketConnection
- type WebSocketConnectionCollection
- type WebSocketConnectionMeta
- type WebSocketPubSubPayload
- type WebSocketRemoval
Constants ¶
This section is empty.
Variables ¶
var BroadcastSockets bool
BroadcastSockets is a flag that determines if web sockets should broadcast to all clients (defaults to true with init())
var CustomLog customLog
CustomLog allows you to set a custom log function for the web server logs that GoCore outputs
var PrimaryGoCoreHTTPServer *http.Server
PrimaryGoCoreHTTPServer is the primary http server that GoCore uses where if you needed to tear it down you could
var StaticWebLocation string
StaticWebLocation is the location of the static web files (defaults to "/web")
var WebSocketCallbacks sync.Map
WebSocketCallbacks is a collection of websocket callbacks
var WebSocketConnections sync.Map
WebSocketConnections is a collection of websocket connections
Functions ¶
func BroadcastWebSocketData ¶
func BroadcastWebSocketData(data []byte)
BroadcastWebSocketData sends a message to all websocket connections
func BroadcastWebSocketJSON ¶
func BroadcastWebSocketJSON(v interface{})
BroadcastWebSocketJSON sends a JSON message to all websocket connections
func GetAllWebSocketMeta ¶
GetAllWebSocketMeta returns all the meta data for all websocket connections
func InitCustomWebConfig ¶
func InitCustomWebConfig(webConfig string)
InitCustomWebCofig initializes the web server with a custom webConfig.json file
func Initialize ¶
Initialize initializes the web server with a full path to your proect and the name of your webConfig.json file.
func InitializeLite ¶
InitializeLite initilizes a basic gin server with no database coupling
func PublishWebSocketJSON ¶
func PublishWebSocketJSON(key string, v interface{})
PublishWebSocketJSON sends a JSON message to all websocket connections
func RegisterWebSocketDataCallback ¶
func RegisterWebSocketDataCallback(callback WebSocketCallback)
RegisterWebSocketDataCallback registers a callback for a websocket data event
func RemoveWebSocketMeta ¶
func RemoveWebSocketMeta(id string)
RemoveWebSocketMeta removes the meta data for a websocket connection
func ReplyToWebSocket ¶
func ReplyToWebSocket(conn *WebSocketConnection, data []byte)
ReplyToWebSocket sends a message to a websocket connection
func ReplyToWebSocketJSON ¶
func ReplyToWebSocketJSON(conn *WebSocketConnection, v interface{})
ReplyToWebSocketJSON sends a JSON message to a websocket connection
func ReplyToWebSocketPubSub ¶
func ReplyToWebSocketPubSub(conn *WebSocketConnection, key string, v interface{})
ReplyToWebSocketPubSub sends a message to all websocket connections
func RunLite ¶
func RunLite(port int)
RunLite is a lite version of Run that does not require a webConfig.json file or any serverSettings information
func SetWebSocketMeta ¶
func SetWebSocketMeta(id string, info *WebSocketConnectionMeta)
SetWebSocketMeta sets the meta data for a websocket connection
func SetWebSocketTimeout ¶
func SetWebSocketTimeout(timeout int)
SetWebSocketTimeout sets the timeout for the websocket connections and will remove ones who havent sent a message within that time frame
Types ¶
type ConcurrentWebSocketCallbackItem ¶
type ConcurrentWebSocketCallbackItem struct { Index int Callback WebSocketCallback }
ConcurrentWebSocketCallbackItem is a concurrent websocket callback item
type ConcurrentWebSocketConnectionItem ¶
type ConcurrentWebSocketConnectionItem struct { Index int Conn *WebSocketConnection }
ConcurrentWebSocketConnectionItem is a concurrent websocket connection item
type GinContextSync ¶
type GinContextSync struct { sync.RWMutex Initialized atomicTypes.AtomicBool Context *gin.Context }
GinContextSync is a sync wrapper for a gin context
type WebSocketCallback ¶
type WebSocketCallback func(conn *WebSocketConnection, c *gin.Context, messageType int, id string, data []byte)
WebSocketCallback is a websocket callback
type WebSocketCallbackSync ¶
WebSocketCallbackSync is a sync wrapper for a websocket callback
func (*WebSocketCallbackSync) Append ¶
func (obj *WebSocketCallbackSync) Append(item WebSocketCallback)
func (*WebSocketCallbackSync) Iter ¶
func (obj *WebSocketCallbackSync) Iter() <-chan ConcurrentWebSocketCallbackItem
type WebSocketConnection ¶
type WebSocketConnection struct { sync.RWMutex Id string Connection *websocket.Conn Req *http.Request Context interface{} ContextString string ContextType string ContextLock sync.RWMutex WriteLock sync.RWMutex LastResponseTime time.Time LastResponseTimeLock sync.RWMutex GinContextSync GinContextSync }
WebSocketConnection is a websocket connection
type WebSocketConnectionCollection ¶
type WebSocketConnectionCollection struct { sync.RWMutex Connections []*WebSocketConnection }
WebSocketConnectionCollection is a collection of websocket connections
func (*WebSocketConnectionCollection) Append ¶
func (wscc *WebSocketConnectionCollection) Append(item *WebSocketConnection)
func (*WebSocketConnectionCollection) Iter ¶
func (wscc *WebSocketConnectionCollection) Iter() <-chan ConcurrentWebSocketConnectionItem
type WebSocketConnectionMeta ¶
type WebSocketConnectionMeta struct { Conn *WebSocketConnection Context interface{} ContextString string ContextType string LastResponseTime atomicTypes.AtomicTime TimeoutOverride atomicTypes.AtomicInt }
WebSocketConnectionMeta is the meta data for a websocket connection
func GetWebSocketMeta ¶
func GetWebSocketMeta(id string) (info *WebSocketConnectionMeta, ok bool)
GetWebSocketMeta returns the meta data for a websocket connection
func (*WebSocketConnectionMeta) GetConnection ¶
func (obj *WebSocketConnectionMeta) GetConnection() (conn *WebSocketConnection)
func (*WebSocketConnectionMeta) SetTimeoutOverride ¶
func (obj *WebSocketConnectionMeta) SetTimeoutOverride(timeout int)
type WebSocketPubSubPayload ¶
type WebSocketPubSubPayload struct { Key string `json:"Key"` Content interface{} `json:"Content"` }
WebSocketPubSubPayload is a websocket pub sub payload
type WebSocketRemoval ¶
type WebSocketRemoval func(info WebSocketConnectionMeta)
WebSocketRemoval a type which removes a websocket callback
var WebSocketRemovalCallback WebSocketRemoval
WebSocketRemovalCallback is a collection of websocket removal callbacks