|
|
@ -11,10 +11,17 @@ import (
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func List[T any](val *[]T) {
|
|
|
|
|
|
|
|
if val != nil && *val == nil {
|
|
|
|
|
|
|
|
*val = []T{}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Call[A, B, C any](
|
|
|
|
func Call[A, B, C any](
|
|
|
|
rpc func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error),
|
|
|
|
rpc func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error),
|
|
|
|
client C,
|
|
|
|
client C,
|
|
|
|
c *gin.Context,
|
|
|
|
c *gin.Context,
|
|
|
|
|
|
|
|
after ...func(resp *B),
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
var req A
|
|
|
|
var req A
|
|
|
|
if err := c.BindJSON(&req); err != nil {
|
|
|
|
if err := c.BindJSON(&req); err != nil {
|
|
|
@ -31,5 +38,8 @@ func Call[A, B, C any](
|
|
|
|
apiresp.GinError(c, err) // RPC调用失败
|
|
|
|
apiresp.GinError(c, err) // RPC调用失败
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, fn := range after {
|
|
|
|
|
|
|
|
fn(data)
|
|
|
|
|
|
|
|
}
|
|
|
|
apiresp.GinSuccess(c, data) // 成功
|
|
|
|
apiresp.GinSuccess(c, data) // 成功
|
|
|
|
}
|
|
|
|
}
|
|
|
|