tencent-connect / botgo

QQ频道机器人 GOSDK
https://bot.q.qq.com/wiki/
Apache License 2.0
297 stars 51 forks source link

考虑OpenAPI提供一套直接返回[]byte的函数 #23

Closed ghost closed 2 years ago

ghost commented 2 years ago

我需要把JSON传递给其他语言,所以直接返回[]byte更合适,不然还要把再json.Marshal转换成[]byte

需要 参数还是*dto.xxx 但返回值是([]byte, error)

vissong commented 2 years ago
// WSPayload websocket 消息结构
type WSPayload struct {
    WSPayloadBase
    Data       interface{} `json:"d,omitempty"`
    RawMessage []byte      `json:"-"` // 原始的 message 数据
}
type ATMessageEventHandler func(event *dto.WSPayload, data *dto.WSATMessageData) error

event 的 RawMessage 可以取到原始数据

ghost commented 2 years ago

那 OpenAPI呢?

vissong commented 2 years ago

openapi 有一个 Transport 方法,可以实现透传,但是需要将需要提交的数据自己进行序列化后传递。

至于具体的操作每个接口的封装,目前还是只能自己 Marshal 一下了

ghost commented 2 years ago

那可以加一套不需要json.Marshal的嘛

ghost commented 2 years ago

我现在就是json.Marshal

vissong commented 2 years ago

那可以加一套不需要json.Marshal的嘛

目前看ROI不是很高,而且会带来大量的多余的方法。为了保持方法的一致性,输入对象,输出 byte,这种做法也不合适。

可以选择使用透传的那个方法,直接传递 marshal 好的数据,接收没有 unmarshal 的数据。

ghost commented 2 years ago

好吧咯