mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-07 19:50:07 +08:00
Merge branch 'v3dev' of github.com:OpenIMSDK/Open-IM-Server into v3dev
This commit is contained in:
commit
e547266755
@ -57,7 +57,7 @@ func run(port int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if client.CreateRpcRootNodes(config.GetServiceNames()); err != nil {
|
if err := client.CreateRpcRootNodes(config.GetServiceNames()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("api init discov client success")
|
fmt.Println("api init discov client success")
|
||||||
|
@ -48,9 +48,7 @@ func (o *FriendApi) AddBlack(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *FriendApi) GetPaginationBlacks(c *gin.Context) {
|
func (o *FriendApi) GetPaginationBlacks(c *gin.Context) {
|
||||||
a2r.Call(friend.FriendClient.GetPaginationBlacks, o.Client, c, func(resp *friend.GetPaginationBlacksResp) {
|
a2r.Call(friend.FriendClient.GetPaginationBlacks, o.Client, c)
|
||||||
a2r.List(&resp.Blacks)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *FriendApi) RemoveBlack(c *gin.Context) {
|
func (o *FriendApi) RemoveBlack(c *gin.Context) {
|
||||||
|
@ -11,17 +11,10 @@ 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 {
|
||||||
@ -38,8 +31,5 @@ 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) // 成功
|
||||||
}
|
}
|
||||||
|
5
pkg/apiresp/format.go
Normal file
5
pkg/apiresp/format.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package apiresp
|
||||||
|
|
||||||
|
type ApiFormat interface {
|
||||||
|
ApiFormat()
|
||||||
|
}
|
@ -34,6 +34,9 @@ func isAllFieldsPrivate(v any) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ApiSuccess(data any) *ApiResponse {
|
func ApiSuccess(data any) *ApiResponse {
|
||||||
|
if format, ok := data.(ApiFormat); ok {
|
||||||
|
format.ApiFormat()
|
||||||
|
}
|
||||||
if isAllFieldsPrivate(data) {
|
if isAllFieldsPrivate(data) {
|
||||||
return &ApiResponse{}
|
return &ApiResponse{}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GrpcClient() grpc.DialOption {
|
func GrpcClient() grpc.DialOption {
|
||||||
return grpc.WithUnaryInterceptor(RpcClientInterceptor)
|
return grpc.WithChainUnaryInterceptor(RpcClientInterceptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RpcClientInterceptor(ctx context.Context, method string, req, resp interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) (err error) {
|
func RpcClientInterceptor(ctx context.Context, method string, req, resp interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) (err error) {
|
||||||
|
@ -153,5 +153,5 @@ func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GrpcServer() grpc.ServerOption {
|
func GrpcServer() grpc.ServerOption {
|
||||||
return grpc.UnaryInterceptor(RpcServerInterceptor)
|
return grpc.ChainUnaryInterceptor(RpcServerInterceptor)
|
||||||
}
|
}
|
||||||
|
@ -529,3 +529,15 @@ func Batch[T any, V any](fn func(T) V, ts []T) []V {
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitSlice[T any](val *[]T) {
|
||||||
|
if val != nil && *val == nil {
|
||||||
|
*val = []T{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitMap[K comparable, V any](val *map[K]V) {
|
||||||
|
if val != nil && *val == nil {
|
||||||
|
*val = map[K]V{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user