Files
marqdo/plugins/web/abi_w8.go
T
cflmyandCursor 4c06851e0e feat(web): Go W-G8 WebSocket routes and access_log
Register route_ws/ws_connect ABIs with an in-process broadcast hub
so offline WS broadcast and access_log smokes pass on libweb.so.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-10 19:31:03 +08:00

51 lines
1.4 KiB
Go

package main
/*
#cgo CFLAGS: -I${SRCDIR}/abi
#include "marqdo_abi_cgo.h"
extern int web_app_route_ws(char *args_json, char **out_json, char **err_msg);
extern int web_ws_connect(char *args_json, char **out_json, char **err_msg);
*/
import "C"
import (
"github.com/marqdo/marqdo/plugins/web/internal/ws"
)
//export web_app_route_ws
func web_app_route_ws(argsJSON *C.char, outJSON **C.char, errMsg **C.char) C.int {
args, err := parseArgs(argsJSON)
if err != nil {
return replyJSON(outJSON, errMsg, nil, err)
}
path, err := argStrReq(args, "path", "路径")
if err != nil {
return replyJSON(outJSON, errMsg, nil, err)
}
out, err := ws.RouteWS(asPageMap(args["app"]), path, args)
return replyJSON(outJSON, errMsg, out, err)
}
//export web_ws_connect
func web_ws_connect(argsJSON *C.char, outJSON **C.char, errMsg **C.char) C.int {
args, err := parseArgs(argsJSON)
if err != nil {
return replyJSON(outJSON, errMsg, nil, err)
}
url, err := argStrReq(args, "url", "地址")
if err != nil {
return replyJSON(outJSON, errMsg, nil, err)
}
message, _ := argStr(args, "message", "消息")
var headers map[string]any
if h, ok := args["headers"]; ok && h != nil {
if m, ok := h.(map[string]any); ok {
headers = m
}
}
timeout := argUint64(args, 30, "timeout_sec", "timeout", "超时")
out := ws.Connect(url, message, headers, timeout)
return replyJSON(outJSON, errMsg, out, nil)
}