Faithful port of the C++ fivenode topology — node hosts the existing N-API
addon, which now links a libfivenode implemented in Go (CGO c-shared)
instead of the Harbour-C core. cmd/libfivenode exports the C ABI the addon
expects (hb_bridge_init/shutdown/handle_request/last_error/set_auth/
clear_auth/free, tfn_register_callbacks). Build:
go build -buildmode=c-shared \
-ldflags="-extldflags=-Wl,-install_name,@rpath/libfivenode.dylib" \
-o native/output/darwin/libfivenode.dylib ./cmd/libfivenode
P1 proven: node → addon → Go hb_bridge_handle_request round-trips a
response in-process (no Harbour-C, no subprocess). P2 wires the real PRG
dispatcher; P3 the npm callbacks (tfn_register_callbacks → Require); P4
the node main-thread marshaling. (goja probe removed — pure-JS only,
insufficient for full npm.)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
// cmd/libfivenode — Go c-shared 구현의 libfivenode (P1 스켈레톤).
|
|
//
|
|
// 기존 C++ fivenode N-API 애드온(fivenode.node)이 기대하는 C ABI 를 Go 가
|
|
// CGO //export 로 제공한다. Harbour-C 코어를 Go 런타임으로 교체하는 첫 단계.
|
|
//
|
|
// go build -buildmode=c-shared -o ../../native/output/darwin/libfivenode.dylib ./cmd/libfivenode
|
|
//
|
|
// P1 목표: 심볼 export + 애드온 로드·왕복(canned 응답). 실제 PRG 디스패치/
|
|
// npm 콜백은 P2~P4 에서.
|
|
package main
|
|
|
|
/*
|
|
#include <stdlib.h>
|
|
*/
|
|
import "C"
|
|
import "unsafe"
|
|
|
|
//export hb_bridge_init
|
|
func hb_bridge_init() C.int {
|
|
return 1
|
|
}
|
|
|
|
//export hb_bridge_shutdown
|
|
func hb_bridge_shutdown() {}
|
|
|
|
//export hb_bridge_handle_request
|
|
func hb_bridge_handle_request(reqJSON *C.char) *C.char {
|
|
// P1: 고정 응답으로 node↔Go 왕복만 증명.
|
|
_ = C.GoString(reqJSON)
|
|
resp := `{"status":200,"headers":{"Content-Type":"text/plain; charset=utf-8"},"body":"hello from Go-implemented libfivenode (N-API P1)"}`
|
|
return C.CString(resp)
|
|
}
|
|
|
|
//export hb_bridge_last_error
|
|
func hb_bridge_last_error() *C.char {
|
|
return C.CString("")
|
|
}
|
|
|
|
//export hb_bridge_set_auth
|
|
func hb_bridge_set_auth(authJSON *C.char) {}
|
|
|
|
//export hb_bridge_clear_auth
|
|
func hb_bridge_clear_auth() {}
|
|
|
|
//export hb_bridge_free
|
|
func hb_bridge_free(ptr *C.char) {
|
|
if ptr != nil {
|
|
C.free(unsafe.Pointer(ptr))
|
|
}
|
|
}
|
|
|
|
// tfn_register_callbacks — 애드온이 npm 콜백 묶음을 등록(P3 에서 저장·사용).
|
|
// P1 에선 void* 로 받아 보관만(구조체 레이아웃은 P3 에서 정의).
|
|
//
|
|
//export tfn_register_callbacks
|
|
func tfn_register_callbacks(cb unsafe.Pointer) {
|
|
npmCallbacks = cb
|
|
}
|
|
|
|
var npmCallbacks unsafe.Pointer
|
|
|
|
func main() {}
|