golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

62 rivejä
1.3 KiB

  1. package config
  2. import (
  3. "context"
  4. "gim/pkg/k8sutil"
  5. "gim/pkg/logger"
  6. "os"
  7. "strconv"
  8. "go.uber.org/zap"
  9. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  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
  22. RedisIP string
  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. }