golang-im聊天
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

60 行
1.4 KiB

  1. package config
  2. import (
  3. "context"
  4. "gim/pkg/k8sutil"
  5. "gim/pkg/logger"
  6. "go.uber.org/zap"
  7. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  8. "os"
  9. "strconv"
  10. )
  11. const (
  12. //RPCListenAddr = ":8000"
  13. //TCPListenAddr = ":8080"
  14. //WSListenAddr = ":8001"
  15. RPCListenAddr = ":8000"
  16. TCPListenAddr = ":8001"
  17. WSListenAddr = ":8002"
  18. )
  19. var (
  20. NameSpace string = "gim"
  21. MySQL string = "root:Fnuo123com@@tcp(119.23.182.117:3306)/gim?charset=utf8&parseTime=true"
  22. RedisIP string = "120.24.28.6:32572"
  23. RedisPassword string = ""
  24. LocalAddr string
  25. PushRoomSubscribeNum int
  26. PushAllSubscribeNum int
  27. )
  28. func Init() {
  29. k8sClient, err := k8sutil.GetK8sClient()
  30. if err != nil {
  31. panic(err)
  32. }
  33. configmap, err := k8sClient.CoreV1().ConfigMaps(NameSpace).Get(context.TODO(), "config", metav1.GetOptions{})
  34. if err != nil {
  35. panic(err)
  36. }
  37. MySQL = configmap.Data["mysql"]
  38. RedisIP = configmap.Data["redisIP"]
  39. RedisPassword = configmap.Data["redisPassword"]
  40. PushRoomSubscribeNum, _ = strconv.Atoi(configmap.Data["pushRoomSubscribeNum"])
  41. if PushRoomSubscribeNum == 0 {
  42. panic("PushRoomSubscribeNum == 0")
  43. }
  44. PushAllSubscribeNum, _ = strconv.Atoi(configmap.Data["pushAllSubscribeNum"])
  45. if PushRoomSubscribeNum == 0 {
  46. panic("PushAllSubscribeNum == 0")
  47. }
  48. LocalAddr = os.Getenv("POD_IP") + RPCListenAddr
  49. logger.Level = zap.DebugLevel
  50. logger.Target = logger.Console
  51. }