From 8aabe605163e25dbfe654fc6f609649bdd3983c7 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Mon, 23 Dec 2024 17:55:01 +0800 Subject: [PATCH] feat: adjust api call rpc --- a2r/api2rpc.go | 2 +- a2r/call_v2.go | 46 ---------------------------------------------- a2r/option.go | 2 -- 3 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 a2r/call_v2.go diff --git a/a2r/api2rpc.go b/a2r/api2rpc.go index 218bc04b..11f264cd 100644 --- a/a2r/api2rpc.go +++ b/a2r/api2rpc.go @@ -35,7 +35,7 @@ type Option[A, B any] struct { RespAfter func(*B) error } -func Call[A, B, C any](rpc func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error), client C, c *gin.Context, opts ...*Option[A, B]) { +func Call[A, B, C any](c *gin.Context, rpc func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error), client C, opts ...*Option[A, B]) { req, err := ParseRequestNotCheck[A](c) if err != nil { apiresp.GinError(c, err) diff --git a/a2r/call_v2.go b/a2r/call_v2.go deleted file mode 100644 index 193eae75..00000000 --- a/a2r/call_v2.go +++ /dev/null @@ -1,46 +0,0 @@ -package a2r - -import ( - "context" - - "github.com/gin-gonic/gin" - "github.com/openimsdk/tools/apiresp" - "github.com/openimsdk/tools/checker" - "google.golang.org/grpc" -) - -func CallV2[A, B any](c *gin.Context, rpc func(ctx context.Context, req *A, options ...grpc.CallOption) (*B, error), opts ...*Option[A, B]) { - req, err := ParseRequestNotCheck[A](c) - if err != nil { - apiresp.GinError(c, err) - return - } - for _, opt := range opts { - if opt.BindAfter == nil { - continue - } - if err := opt.BindAfter(req); err != nil { - apiresp.GinError(c, err) // args option error - return - } - } - if err := checker.Validate(req); err != nil { - apiresp.GinError(c, err) // args option error - return - } - resp, err := rpc(c, req) - if err != nil { - apiresp.GinError(c, err) // rpc call failed - return - } - for _, opt := range opts { - if opt.RespAfter == nil { - continue - } - if err := opt.RespAfter(resp); err != nil { - apiresp.GinError(c, err) // resp option error - return - } - } - apiresp.GinSuccess(c, resp) // rpc call success -} diff --git a/a2r/option.go b/a2r/option.go index fa83cd7e..4075c97a 100644 --- a/a2r/option.go +++ b/a2r/option.go @@ -17,5 +17,3 @@ func respNilReplace[T any](data *T) error { mw.ReplaceNil(data) return nil } - -// ------------------------------------------------------------------------------------------------------------------