feat: refactor logger to avoid standard output in log method and update JSPlugin HTTP handler to use goja.Callable
All checks were successful
Build Multi-Platform Binaries / build-frontend (push) Successful in 3m24s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 4m55s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 8m31s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 7m19s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 5m20s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 3m45s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 7m42s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 6m59s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Successful in 8m41s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 4m54s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Successful in 7m23s
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Successful in 10m48s

This commit is contained in:
2026-01-05 20:13:06 +08:00
parent cbd3ba0a4f
commit c1f6e0bdcf
2 changed files with 25 additions and 8 deletions

View File

@@ -104,12 +104,8 @@ func (l *Logger) log(level LogLevel, source, format string, args ...interface{})
Source: source, Source: source,
} }
// 输出到标准输出 // 注意不在这里输出到标准输出因为调用方logf/logErrorf/logWarnf已经调用了 log.Print
fmt.Printf("%s [%s] [%s] %s\n", // 这里只负责:缓冲区存储、文件写入、订阅者通知
time.Now().Format("2006-01-02 15:04:05"),
entry.Level,
entry.Source,
entry.Message)
// 添加到环形缓冲区 // 添加到环形缓冲区
l.bufferMu.Lock() l.bufferMu.Lock()

View File

@@ -390,7 +390,7 @@ func (p *JSPlugin) createHttpAPI() map[string]interface{} {
} }
// httpServe 启动 HTTP 服务处理连接 // httpServe 启动 HTTP 服务处理连接
func (p *JSPlugin) httpServe(conn net.Conn, handler func(map[string]interface{}) map[string]interface{}) { func (p *JSPlugin) httpServe(conn net.Conn, handler goja.Callable) {
defer conn.Close() defer conn.Close()
buf := make([]byte, 4096) buf := make([]byte, 4096)
@@ -400,7 +400,28 @@ func (p *JSPlugin) httpServe(conn net.Conn, handler func(map[string]interface{})
} }
req := parseHTTPRequest(buf[:n]) req := parseHTTPRequest(buf[:n])
resp := handler(req)
// 调用 JS handler 函数
result, err := handler(goja.Undefined(), p.vm.ToValue(req))
if err != nil {
fmt.Printf("[JS:%s] HTTP handler error: %v\n", p.name, err)
conn.Write([]byte("HTTP/1.1 500 Internal Server Error\r\n\r\n"))
return
}
// 将结果转换为 map
if result == nil || goja.IsUndefined(result) || goja.IsNull(result) {
conn.Write([]byte("HTTP/1.1 200 OK\r\n\r\n"))
return
}
resp := make(map[string]interface{})
respObj := result.ToObject(p.vm)
for _, key := range respObj.Keys() {
val := respObj.Get(key)
resp[key] = val.Export()
}
writeHTTPResponse(conn, resp) writeHTTPResponse(conn, resp)
} }