yinbentan
2024-07-08 f4508a84236a4aff1c7b5bfa17a14a8ff95728ba
接口调用报错处理
2个文件已修改
14 ■■■■ 已修改文件
proto/init_client/init_client.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
proto/user/server.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
proto/init_client/init_client.go
@@ -31,10 +31,12 @@
        logx.Errorf("grpc dial product service error: %v", err.Error())
        return
    }
    AdminConn, err = grpc.Dial(conf.GrpcServerConf.AdminAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
    if err != nil {
        logx.Errorf("grpc dial product service error: %v", err.Error())
        return
    if len(conf.GrpcServerConf.AdminAddr) > 0 {
        AdminConn, err = grpc.Dial(conf.GrpcServerConf.AdminAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
        if err != nil {
            logx.Errorf("grpc dial product service error: %v", err.Error())
            return
        }
    }
}
proto/user/server.go
@@ -2,11 +2,15 @@
import (
    "context"
    "errors"
    "wms/pkg/logx"
    "wms/proto/init_client"
)
func GetUserList() ([]*GetUserRequest, error) {
    if init_client.AdminConn == nil {
        return nil, errors.New("grpc.ClientConnInterface AdminConn is nil")
    }
    cli := NewUserServiceClient(init_client.AdminConn)
    list, err := cli.GetUserList(context.Background(), &GetUserRequest{})
    if err != nil {