mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-03 06:35:00 +08:00
- Added `GetGJSONBytesNoCopy` in `internal/util` for safe, no-copy JSON parse operations leveraging `unsafe`. - Replaced `gjson.GetBytes` with the new helper in key payload processing paths (`kimi_executor`, `vertex_payload_helpers`, etc.) to improve performance. - Added unit tests for behavior validation, including edge cases with empty input.
18 lines
546 B
Go
18 lines
546 B
Go
package util
|
|
|
|
import "testing"
|
|
|
|
func TestGetGJSONBytesNoCopy(t *testing.T) {
|
|
input := []byte(`{"request":{"contents":[{"role":"user"}]}}`)
|
|
contents := GetGJSONBytesNoCopy(input, "request.contents")
|
|
if !contents.IsArray() || contents.Get("0.role").String() != "user" {
|
|
t.Fatalf("request.contents = %s, want user content array", contents.Raw)
|
|
}
|
|
}
|
|
|
|
func TestGetGJSONBytesNoCopyEmptyInput(t *testing.T) {
|
|
if result := GetGJSONBytesNoCopy(nil, "contents"); result.Exists() {
|
|
t.Fatalf("empty input result = %s, want missing", result.Raw)
|
|
}
|
|
}
|