config.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package config
  2. import (
  3. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
  4. "github.com/zeromicro/go-zero/core/conf"
  5. "github.com/zeromicro/go-zero/core/discov"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "github.com/zeromicro/go-zero/zrpc"
  8. "userCenter/entity"
  9. )
  10. type Config struct {
  11. zrpc.RpcServerConf
  12. FileSystemConf zrpc.RpcClientConf
  13. CalleeId string // 服务名字
  14. ResourceEtcdConf zrpc.RpcClientConf //资源中台
  15. Node int // 节点
  16. Mysql Mysql
  17. BaseMysql Mysql
  18. Logx logx.LogConf
  19. IsRun bool //定时任务是否开启
  20. CheckEntIsExpire string //
  21. DoMain string
  22. RedisAddrees []string
  23. RedisOutTime int64
  24. InternalTime int64
  25. Mongo struct {
  26. Main *MongoStruct
  27. }
  28. BigMemberOff bool
  29. CommonlySize int64 //常用功能设置数量
  30. ManagerUserIds []string
  31. }
  32. type MongoStruct struct {
  33. Address string `json:"address"`
  34. Size int `json:"size"`
  35. DbName string `json:"dbName"`
  36. UserName string `json:"userName,optional"`
  37. Password string `json:"password,optional"`
  38. Collection string `json:"collection,optional"`
  39. CollectionBack string `json:"collectionBack,optional"`
  40. MaxOpenConns int `json:"maxOpenConns,optional"`
  41. MaxIdleConns int `json:"maxIdleConns,optional"`
  42. }
  43. var (
  44. ConfigJson Config
  45. ManagerUserIdsMap = map[string]bool{}
  46. )
  47. type Mysql struct {
  48. DbName string `json:"dbName"`
  49. Address string `json:"address"`
  50. UserName string `json:"userName"`
  51. PassWord string `json:"passWord"`
  52. MaxOpenConns int `json:"maxOpenConns"`
  53. MaxIdleConns int `json:"maxIdleConns"`
  54. }
  55. func init() {
  56. conf.MustLoad("etc/usercenter.yaml", &ConfigJson)
  57. //初始化资源中台相关
  58. resourceClient := zrpc.MustNewClient(zrpc.RpcClientConf{
  59. Etcd: discov.EtcdConf{
  60. Hosts: ConfigJson.ResourceEtcdConf.Etcd.Hosts,
  61. Key: ConfigJson.ResourceEtcdConf.Etcd.Key,
  62. },
  63. })
  64. entity.ResourceLib = resource.NewResource(resourceClient)
  65. //
  66. if len(ConfigJson.ManagerUserIds) > 0 {
  67. for _, v := range ConfigJson.ManagerUserIds {
  68. ManagerUserIdsMap[v] = true
  69. }
  70. }
  71. }