From a23b96a87a9d3183a33d45e8d9cf91efd92cfed8 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Fri, 22 Nov 2024 21:03:18 +0800 Subject: [PATCH] 12 --- config/config.go | 44 ++++++++++++++++++++++++-------------------- pkg/rpc/rpc.go | 6 +++--- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/config/config.go b/config/config.go index ad48240..1b8ccf6 100644 --- a/config/config.go +++ b/config/config.go @@ -1,9 +1,13 @@ package config import ( + "context" + "egg-im/pkg/k8sutil" "egg-im/pkg/logger" "go.uber.org/zap" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "os" + "strconv" ) const ( @@ -27,26 +31,26 @@ var ( ) func Init() { - //k8sClient, err := k8sutil.GetK8sClient() - //if err != nil { - // panic(err) - //} - //configmap, err := k8sClient.CoreV1().ConfigMaps(NameSpace).Get(context.TODO(), "config", metav1.GetOptions{}) - //if err != nil { - // panic(err) - //} - // - //MySQL = configmap.Data["mysql"] - //RedisIP = configmap.Data["redisIP"] - //RedisPassword = configmap.Data["redisPassword"] - //PushRoomSubscribeNum, _ = strconv.Atoi(configmap.Data["pushRoomSubscribeNum"]) - //if PushRoomSubscribeNum == 0 { - // panic("PushRoomSubscribeNum == 0") - //} - //PushAllSubscribeNum, _ = strconv.Atoi(configmap.Data["pushAllSubscribeNum"]) - //if PushRoomSubscribeNum == 0 { - // panic("PushAllSubscribeNum == 0") - //} + k8sClient, err := k8sutil.GetK8sClient() + if err != nil { + panic(err) + } + configmap, err := k8sClient.CoreV1().ConfigMaps(NameSpace).Get(context.TODO(), "config", metav1.GetOptions{}) + if err != nil { + panic(err) + } + + MySQL = configmap.Data["mysql"] + RedisIP = configmap.Data["redisIP"] + RedisPassword = configmap.Data["redisPassword"] + PushRoomSubscribeNum, _ = strconv.Atoi(configmap.Data["pushRoomSubscribeNum"]) + if PushRoomSubscribeNum == 0 { + panic("PushRoomSubscribeNum == 0") + } + PushAllSubscribeNum, _ = strconv.Atoi(configmap.Data["pushAllSubscribeNum"]) + if PushRoomSubscribeNum == 0 { + panic("PushAllSubscribeNum == 0") + } LocalAddr = os.Getenv("POD_IP") + RPCListenAddr diff --git a/pkg/rpc/rpc.go b/pkg/rpc/rpc.go index 6d847fb..d028395 100644 --- a/pkg/rpc/rpc.go +++ b/pkg/rpc/rpc.go @@ -58,10 +58,10 @@ func initConnectIntClient() { } func initBusinessIntClient() { - conn, err := grpc.DialContext(context.TODO(), "127.0.0.1:8000", grpc.WithInsecure(), - grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name))) - //conn, err := grpc.DialContext(context.TODO(), k8s.GetK8STarget("egg-im", "business", "8000"), grpc.WithInsecure(), + //conn, err := grpc.DialContext(context.TODO(), "127.0.0.1:8000", grpc.WithInsecure(), // grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name))) + conn, err := grpc.DialContext(context.TODO(), k8s.GetK8STarget("egg-im", "business", "8000"), grpc.WithInsecure(), + grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name))) if err != nil { panic(err) }