liujiandao
2024-01-11 40e540f8ca398fee68f4520dbebd6db6fe2e164c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package grpc_init
 
import (
    "aps_crm/conf"
    "aps_crm/pkg/logx"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials/insecure"
)
 
var (
    ProductInventoryServiceConn *grpc.ClientConn
    CrmApsGrpcServiceConn       *grpc.ClientConn
)
 
func InitCrmApsGrpcServiceConn() {
    var err error
    CrmApsGrpcServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.Aps, grpc.WithTransportCredentials(insecure.NewCredentials()))
    if err != nil {
        logx.Errorf("grpc dial InitCrmApsGrpcServiceConn service error: %v", err.Error())
        return
    }
}
 
func CloseCrmApsGrpcServiceConn() {
    if CrmApsGrpcServiceConn != nil {
        CrmApsGrpcServiceConn.Close()
    }
}
 
func InitProductInventoryServiceConn() {
    var err error
    ProductInventoryServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.WMS, grpc.WithTransportCredentials(insecure.NewCredentials()))
    if err != nil {
        logx.Errorf("grpc dial product service error: %v", err.Error())
        return
    }
}
 
func CloseProductInventoryServiceConn() {
    if ProductInventoryServiceConn != nil {
        ProductInventoryServiceConn.Close()
    }
}