浏览代码

feat(http): 更新回复函数签名以支持上下文传递

- 在 ReplyFunc 类型中增加 http.Context 参数
- 修改 DefaultFunc 函数签名以接收上下文参数
- 引入 kratos/v2 transport/http 包以使用 Context 类型
dcsunny 1 周之前
父节点
当前提交
adf7dde65a
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      http/reply/reply.go

+ 6 - 2
http/reply/reply.go

@@ -1,16 +1,20 @@
 package reply
 
+import (
+	"github.com/go-kratos/kratos/v2/transport/http"
+)
+
 type SuccessReply struct {
 	Code    int32       `json:"code"`
 	Message string      `json:"message"`
 	Data    interface{} `json:"data"`
 }
 
-type ReplyFunc func(req any) (any, error)
+type ReplyFunc func(ctx http.Context, req any) (any, error)
 
 var reply = DefaultFunc
 
-func DefaultFunc(out any) (any, error) {
+func DefaultFunc(ctx http.Context, out any) (any, error) {
 	success := &SuccessReply{
 		Code: 0,
 	}