api nil slice map

This commit is contained in:
withchao
2023-07-06 15:09:41 +08:00
parent ff22ea7108
commit f6756008b0
5 changed files with 21 additions and 13 deletions
-10
View File
@@ -11,17 +11,10 @@ import (
"google.golang.org/grpc"
)
func List[T any](val *[]T) {
if val != nil && *val == nil {
*val = []T{}
}
}
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,
after ...func(resp *B),
) {
var req A
if err := c.BindJSON(&req); err != nil {
@@ -38,8 +31,5 @@ func Call[A, B, C any](
apiresp.GinError(c, err) // RPC调用失败
return
}
for _, fn := range after {
fn(data)
}
apiresp.GinSuccess(c, data) // 成功
}