api to rpc

This commit is contained in:
withchao
2023-02-27 14:44:14 +08:00
parent 03ccd0131a
commit 0411a5045b
9 changed files with 173 additions and 16 deletions
+49
View File
@@ -0,0 +1,49 @@
package api2rpc
import (
"context"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
)
type FUNC[E, C, D any] func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)
// Call1 TEST
func Call1[A, B, C, D, E any](
apiReq *A,
apiResp *B,
rpc FUNC[E, C, D],
//client func() (E, error),
c *gin.Context,
before func(apiReq *A, rpcReq *C, bind func() error) error,
after func(rpcResp *D, apiResp *B, bind func() error) error,
) {
}
func Call2[C, D, E any](
rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error),
client func() (E, error),
c *gin.Context,
) {
}
func Call3[C, D, E any](
rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error),
//client func() (E, error),
c *gin.Context,
) {
}
func Call4[C, D, E any](
rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error),
c *gin.Context,
) {
}
func Call10[A, B, C, D, E any](apiReq A, apiResp B, client func() (E, error), call func(client E, rpcReq C) (D, error)) {
}
+1 -1
View File
@@ -9,7 +9,7 @@ import (
type rpcFunc[E, C, D any] func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)
func New[A, B, C, D any, E any](apiReq *A, apiResp *B, rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)) RpcCall[A, B, C, D, E] {
func New[A, B, C, D, E any](apiReq *A, apiResp *B, rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)) RpcCall[A, B, C, D, E] {
return &rpcCall[A, B, C, D, E]{
apiReq: apiReq,
apiResp: apiResp,