diff --git a/internal/api/friend.go b/internal/api/friend.go index 8fe9033d5..fd4369e41 100644 --- a/internal/api/friend.go +++ b/internal/api/friend.go @@ -48,7 +48,9 @@ func (o *FriendApi) AddBlack(c *gin.Context) { } func (o *FriendApi) GetPaginationBlacks(c *gin.Context) { - a2r.Call(friend.FriendClient.GetPaginationBlacks, o.Client, c) + a2r.Call(friend.FriendClient.GetPaginationBlacks, o.Client, c, func(resp *friend.GetPaginationBlacksResp) { + a2r.List(&resp.Blacks) + }) } func (o *FriendApi) RemoveBlack(c *gin.Context) { diff --git a/pkg/a2r/api2rpc.go b/pkg/a2r/api2rpc.go index 50d5b2ac3..9cd1c5c17 100644 --- a/pkg/a2r/api2rpc.go +++ b/pkg/a2r/api2rpc.go @@ -11,10 +11,17 @@ 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 { @@ -31,5 +38,8 @@ func Call[A, B, C any]( apiresp.GinError(c, err) // RPC调用失败 return } + for _, fn := range after { + fn(data) + } apiresp.GinSuccess(c, data) // 成功 }