web

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 35 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"

	WaveZoneFileInfoHeaderKey = "X-ZoneFileInfo"
)

Header constants

View Source
const DefaultCommandTimeout = 2 * time.Second
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
View Source
const TransparentGif64 = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
View Source
const WSStatePacketChSize = 20
View Source
const WSStateReconnectTime = 30 * time.Second
View Source
const WebSocketChannelSize = 128

Variables

View Source
var GlobalLock = &sync.Mutex{}
View Source
var RouteToConnMap = map[string]*StableConnInfo{} // stableid => StableConnInfo
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 HandleWs

func HandleWs(w http.ResponseWriter, r *http.Request)

func HandleWsInternal

func HandleWsInternal(w http.ResponseWriter, r *http.Request) error

func MakeTCPListener

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

func MakeUnixListener

func MakeUnixListener() (net.Listener, error)

func ReadLoop

func ReadLoop(conn *websocket.Conn, outputCh chan any, closeCh chan any, rpcInputCh chan baseds.RpcInputChType, routeId string)

func RunWebServer

func RunWebServer(listener net.Listener)

blocking

func RunWebSocketServer

func RunWebSocketServer(listener net.Listener)

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 any, closeCh chan any, routeId string)

func WritePing

func WritePing(conn *websocket.Conn) error

Types

type ClientActiveState

type ClientActiveState struct {
	Fg     bool `json:"fg"`
	Active bool `json:"active"`
	Open   bool `json:"open"`
}

type StableConnInfo

type StableConnInfo struct {
	ConnId string
	LinkId baseds.LinkId
}

type WSBatcher added in v0.16.0

type WSBatcher struct {
	// contains filtered or unexported fields
}

WSBatcher coalesces outbound JSON WebSocket messages within a 16ms window. Wire format: [count uint32 LE][len1 uint32 LE][msg1 bytes][len2 uint32 LE][msg2 bytes]... Control messages (ping/pong/error type) bypass batching and are sent immediately. Thread-safe: Send() may be called from multiple goroutines.

func (*WSBatcher) Send added in v0.16.0

func (b *WSBatcher) Send(msg []byte) error

Send queues msg for batched delivery. If this is the first message in a new batch window, a flush timer is started. Thread-safe.

func (*WSBatcher) SendImmediate added in v0.16.0

func (b *WSBatcher) SendImmediate(msg []byte) error

SendImmediate bypasses batching — used for ping/pong and close frames.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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