refactor(web): start Go ABI rewrite of plugins/web (W-G0)
Archive the Rust web plugin and add a Go c-shared skeleton with ABI v2 bridge, build script, design doc/ADR, and smoke test so multi-language plugins and full web parity can proceed wave by wave. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fb6254e501
commit
ca40c698a2
42 files changed
+955
-3
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package page
|
||||
|
||||
import "strconv"
|
||||
|
||||
// New builds a page bag (ABI web_page_new), matching the Rust plugin shape.
|
||||
func New(args map[string]any) map[string]any {
|
||||
title := strOpt(args, "title", "Marqdo Web")
|
||||
intro := strOpt(args, "intro", "")
|
||||
out := map[string]any{
|
||||
"title": title,
|
||||
"intro": intro,
|
||||
}
|
||||
if s, ok := strAny(args, "shell_css", "壳样式"); ok {
|
||||
out["shell_css"] = s
|
||||
}
|
||||
if s, ok := strAny(args, "layout", "布局"); ok {
|
||||
out["layout"] = s
|
||||
}
|
||||
if s, ok := strAny(args, "asset_version", "资源版本"); ok {
|
||||
out["asset_version"] = s
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func strOpt(args map[string]any, key, def string) string {
|
||||
if s, ok := strAny(args, key); ok {
|
||||
return s
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func strAny(args map[string]any, keys ...string) (string, bool) {
|
||||
for _, k := range keys {
|
||||
v, ok := args[k]
|
||||
if !ok || v == nil {
|
||||
continue
|
||||
}
|
||||
switch t := v.(type) {
|
||||
case string:
|
||||
return t, true
|
||||
case float64:
|
||||
if t == float64(int64(t)) {
|
||||
return strconv.FormatInt(int64(t), 10), true
|
||||
}
|
||||
return strconv.FormatFloat(t, 'f', -1, 64), true
|
||||
case bool:
|
||||
return strconv.FormatBool(t), true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package page_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/marqdo/marqdo/plugins/web/internal/page"
|
||||
)
|
||||
|
||||
func TestNewDefaults(t *testing.T) {
|
||||
p := page.New(map[string]any{})
|
||||
if p["title"] != "Marqdo Web" {
|
||||
t.Fatalf("title=%v", p["title"])
|
||||
}
|
||||
if p["intro"] != "" {
|
||||
t.Fatalf("intro=%v", p["intro"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewZhAliases(t *testing.T) {
|
||||
p := page.New(map[string]any{
|
||||
"title": "T",
|
||||
"壳样式": "minimal",
|
||||
"布局": "bare",
|
||||
"资源版本": "v1",
|
||||
})
|
||||
if p["shell_css"] != "minimal" || p["layout"] != "bare" || p["asset_version"] != "v1" {
|
||||
t.Fatalf("%v", p)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package plugin
|
||||
|
||||
// HostFns holds callbacks into the Marqdo host (valid after marqdo_plugin_init).
|
||||
type HostFns struct {
|
||||
Query func(name, argsJSON string) (string, error)
|
||||
}
|
||||
|
||||
var host HostFns
|
||||
|
||||
// SetHost stores host callbacks from ABI init.
|
||||
func SetHost(h HostFns) { host = h }
|
||||
|
||||
// Shutdown clears plugin global state (HTTP servers, pools, …).
|
||||
func Shutdown() {
|
||||
host = HostFns{}
|
||||
}
|
||||
|
||||
// Query runs an allowlisted host_query.
|
||||
func Query(name, argsJSON string) (string, error) {
|
||||
if host.Query == nil {
|
||||
return "", errString("host_query not available")
|
||||
}
|
||||
return host.Query(name, argsJSON)
|
||||
}
|
||||
|
||||
type errString string
|
||||
|
||||
func (e errString) Error() string { return string(e) }
|
||||
Reference in new issue
Block a user