Documentation
¶
Index ¶
- Constants
- Variables
- func GetAllWSInfo() map[string]WSInfo
- func GetFileSystem() http.FileSystem
- func HandleWs(w http.ResponseWriter, r *http.Request)
- func HandleWsInternal(w http.ResponseWriter, r *http.Request) error
- func MakeTCPListener(serviceName string, addr string) (net.Listener, error)
- func ReadLoop(conn *websocket.Conn, outputCh chan WSEventType, closeCh chan any, ...)
- func RunWebServer(ctx context.Context, overridePort int) (int, error)
- func ServeIndexOrFile(w http.ResponseWriter, r *http.Request, fs http.FileSystem)
- func WriteJsonError(w http.ResponseWriter, errVal error)
- func WriteJsonSuccess(w http.ResponseWriter, data interface{})
- func WriteLoop(conn *websocket.Conn, outputCh chan WSEventType, closeCh chan any, ...)
- func WritePing(conn *websocket.Conn) error
- type TrayAppRunInfo
- type WSEventType
- type WSInfo
- type WebFnOpts
- type WebFnType
- type WebSocketModel
Constants ¶
const ( CacheControlHeaderKey = "Cache-Control" CacheControlHeaderNoCache = "no-cache" ContentTypeHeaderKey = "Content-Type" ContentTypeJson = "application/json" ContentTypeBinary = "application/octet-stream" ContentLengthHeaderKey = "Content-Length" LastModifiedHeaderKey = "Last-Modified" )
Header constants
const EventType_Ping = "ping"
const EventType_Pong = "pong"
const EventType_Rpc = "rpc"
const HttpMaxHeaderBytes = 60000
const HttpReadTimeout = 5 * time.Second
const HttpTimeoutDuration = 21 * time.Second
const HttpWriteTimeout = 21 * time.Second
Variables ¶
var ConnMap = utilds.MakeSyncMap[string, *WebSocketModel]()
Functions ¶
func GetAllWSInfo ¶
GetAllWSInfo returns a map of connection ID to WSInfo for all WebSocket connections
func GetFileSystem ¶
func GetFileSystem() http.FileSystem
GetFileSystem returns the appropriate filesystem to use based on environment In development mode, it returns the local filesystem In production mode, it returns the embedded filesystem
func HandleWs ¶
func HandleWs(w http.ResponseWriter, r *http.Request)
HandleWs handles WebSocket connections This is now served through the HTTP server on the same port
func HandleWsInternal ¶
func HandleWsInternal(w http.ResponseWriter, r *http.Request) error
func RunWebServer ¶
RunWebServer initializes and runs the HTTP server (which also handles WebSockets) If overridePort is non-zero, it will be used instead of the default port Returns the port on which the server is running
func ServeIndexOrFile ¶
func ServeIndexOrFile(w http.ResponseWriter, r *http.Request, fs http.FileSystem)
ServeIndexOrFile serves either the requested file or falls back to index.html This is necessary for SPA (Single Page Application) routing
func WriteJsonError ¶
func WriteJsonError(w http.ResponseWriter, errVal error)
func WriteJsonSuccess ¶
func WriteJsonSuccess(w http.ResponseWriter, data interface{})
Types ¶
type TrayAppRunInfo ¶
type TrayAppRunInfo struct {
AppRunId string `json:"apprunid"`
AppName string `json:"appname"`
IsRunning bool `json:"isrunning"`
StartTime int64 `json:"starttime"`
}
TrayAppRunInfo contains minimal app run information for the tray app
type WSEventType ¶
type WebSocketModel ¶
type WebSocketModel struct {
ConnId string
RouteId string
Conn *websocket.Conn
OutputCh chan WSEventType
}