app

package module
v0.0.0-...-a499989 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2023 License: MIT Imports: 24 Imported by: 1

Documentation

Overview

Package app is a package that contains the core functionality of the GoCore framework and websocket functionality

Index

Constants

This section is empty.

Variables

View Source
var BroadcastSockets bool

BroadcastSockets is a flag that determines if web sockets should broadcast to all clients (defaults to true with init())

View Source
var CustomLog customLog

CustomLog allows you to set a custom log function for the web server logs that GoCore outputs

View Source
var PrimaryGoCoreHTTPServer *http.Server

PrimaryGoCoreHTTPServer is the primary http server that GoCore uses where if you needed to tear it down you could

View Source
var StaticWebLocation string

StaticWebLocation is the location of the static web files (defaults to "/web")

View Source
var WebSocketCallbacks sync.Map

WebSocketCallbacks is a collection of websocket callbacks

View Source
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 CloseAllSockets

func CloseAllSockets()

CloseAllSockets closes all web sockets

func GetAllWebSocketMeta

func GetAllWebSocketMeta() (items *sync.Map)

GetAllWebSocketMeta returns all the meta data for all websocket connections

func Init

func Init()

Init initializes the web server with the default webConfig.json file

func InitCustomWebConfig

func InitCustomWebConfig(webConfig string)

InitCustomWebCofig initializes the web server with a custom webConfig.json file

func Initialize

func Initialize(path string, config string)

Initialize initializes the web server with a full path to your proect and the name of your webConfig.json file.

func InitializeLite

func InitializeLite(secureHeaders bool, allowedHosts []string) (err error)

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 Run

func Run()

Run starts the server (Typically for a full GoCore server)

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 RunServer

func RunServer()

RunServer Blocking forever with ListenAndServe!!

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

type WebSocketCallbackSync struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

WebSocketCallbackSync is a sync wrapper for a websocket callback

func (*WebSocketCallbackSync) Append

func (obj *WebSocketCallbackSync) Append(item WebSocketCallback)

func (*WebSocketCallbackSync) Iter

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 (*WebSocketConnectionCollection) Iter

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

Directories

Path Synopsis
api module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL