feat: add execution history queries and preserve bounded JSON payloads
This commit is contained in:
18
internal/jsonwire/marshal.go
Normal file
18
internal/jsonwire/marshal.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Package jsonwire 统一 JSON 传输与回执编码;响应以 application/json 提供,不嵌入 HTML。
|
||||
package jsonwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// Marshal 保留 RawMessage 数字文本,避免 HTML 转义把合法载荷放大到传输上限之外。
|
||||
func Marshal(value any) ([]byte, error) {
|
||||
var buffer bytes.Buffer
|
||||
encoder := json.NewEncoder(&buffer)
|
||||
encoder.SetEscapeHTML(false)
|
||||
if err := encoder.Encode(value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bytes.TrimSuffix(buffer.Bytes(), []byte{'\n'}), nil
|
||||
}
|
||||
Reference in New Issue
Block a user