1 Star 0 Fork 0

h79/goim

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
response.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-07-22 18:09 . init
package rpc
import (
"gitee.com/h79/goutils/api"
"gitee.com/h79/goutils/common/config"
"gitee.com/h79/goutils/common/result"
"gitee.com/h79/goutils/common/timer"
pb "gitee.com/h79/protobuffs"
)
func CreateEvent(evType int32, content []byte) *pb.Event {
return &pb.Event{
EventType: evType,
ContentType: api.JSON,
Content: string(content),
}
}
func CreateResponseWithHead(recvAt int64, req *pb.Request, code int32, desc string) *pb.Response {
return CreateResponse(recvAt, req.GetTimeAt(), req.GetSeqId(), code, desc)
}
func ReturnResponse(rsp *pb.Response) {
end := timer.CurrentMS()
rsp.SpendAt = end - rsp.TimeAt
}
func CreateResponse(recvAt, clientAt int64, seqId string, code int32, desc string) *pb.Response {
rsp := &pb.Response{
Version: config.Version,
Source: config.Source,
SeqId: seqId,
Errno: code,
Error: "",
Code: code,
Desc: desc,
ServerAt: timer.CurrentMS(),
}
rsp.TimeAt = recvAt
rsp.DiffAt = rsp.ServerAt - clientAt
return rsp
}
func WithError(res *pb.Response, err error) *pb.Response {
if err == nil {
return res
}
r := result.WithErr(err)
res.Code = r.Errno
res.SubCode = r.SubCode
res.Desc = r.Desc
res.Msg = r.Msg
res.Errno = r.Errno
res.Error = r.Error()
return res
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goim.git
git@gitee.com:h79/goim.git
h79
goim
goim
v0.3.10

搜索帮助

0d507c66 1850385 C8b1a773 1850385