1
0
mirror of https://github.com/fumiama/go-onebot-agent.git synced 2026-06-05 02:00:23 +08:00

fix: marshal APIResponse error

This commit is contained in:
源文雨
2026-04-25 17:39:14 +08:00
parent 921eee5b68
commit 9c92a03776
2 changed files with 21 additions and 0 deletions

View File

@@ -51,6 +51,9 @@ type APIResponse struct {
// String dumps JSON without tailing \n
func (resp *APIResponse) String() string {
sb := strings.Builder{}
if len(resp.Data) == 0 {
resp.Data = []byte(`null`)
}
err := json.NewEncoder(&sb).Encode(resp)
if err != nil {
panic(errors.Wrap(err, "unexpected"))

18
types_test.go Normal file
View File

@@ -0,0 +1,18 @@
package goba
import "testing"
func TestMarshalAPIResponse(t *testing.T) {
rsp := &APIResponse{
Status: "error",
Data: []byte(`null`),
Message: "12345",
}
t.Log(rsp.String())
rsp = &APIResponse{
Status: "error",
Data: []byte(``),
Message: "12345",
}
t.Log(rsp.String())
}