web

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

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

View Source
const EventType_Ping = "ping"
View Source
const EventType_Pong = "pong"
View Source
const EventType_Rpc = "rpc"
View Source
const HttpMaxHeaderBytes = 60000
View Source
const HttpReadTimeout = 5 * time.Second
View Source
const HttpTimeoutDuration = 21 * time.Second
View Source
const HttpWriteTimeout = 21 * time.Second

Variables

View Source
var WebSocketUpgrader = websocket.Upgrader{
	ReadBufferSize:   4 * 1024,
	WriteBufferSize:  32 * 1024,
	HandshakeTimeout: 1 * time.Second,
	CheckOrigin:      func(r *http.Request) bool { return true },
}

Functions

func GetAllWSInfo

func GetAllWSInfo() map[string]WSInfo

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 MakeTCPListener

func MakeTCPListener(serviceName string, addr string) (net.Listener, error)

func ReadLoop

func ReadLoop(conn *websocket.Conn, outputCh chan WSEventType, closeCh chan any, connId string, rpcCh chan []byte)

func RunWebServer

func RunWebServer(ctx context.Context, overridePort int) (int, error)

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{})

func WriteLoop

func WriteLoop(conn *websocket.Conn, outputCh chan WSEventType, closeCh chan any, connId string)

func WritePing

func WritePing(conn *websocket.Conn) error

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 WSEventType struct {
	Type string `json:"type"`
	Ts   int64  `json:"ts"`
	Data any    `json:"data,omitempty"`
}

type WSInfo

type WSInfo struct {
	ConnId  string `json:"connid"`
	RouteId string `json:"routeid"`
}

WSInfo contains information about a WebSocket connection

type WebFnOpts

type WebFnOpts struct {
	AllowCaching bool
	JsonErrors   bool
}

type WebFnType

type WebFnType = func(http.ResponseWriter, *http.Request)

func WebFnWrap

func WebFnWrap(opts WebFnOpts, fn WebFnType) WebFnType

type WebSocketModel

type WebSocketModel struct {
	ConnId   string
	RouteId  string
	Conn     *websocket.Conn
	OutputCh chan WSEventType
}

Jump to

Keyboard shortcuts

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