config.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 int
  24. InternalTime int
  25. Mongo struct {
  26. Main *MongoStruct
  27. }
  28. BigMemberOff bool
  29. CommonlySize int //常用功能设置数量
  30. }
  31. type MongoStruct struct {
  32. Address string `json:"address"`
  33. Size int `json:"size"`
  34. DbName string `json:"dbName"`
  35. UserName string `json:"userName,optional"`
  36. Password string `json:"password,optional"`
  37. Collection string `json:"collection,optional"`
  38. CollectionBack string `json:"collectionBack,optional"`
  39. MaxOpenConns int `json:"maxOpenConns,optional"`
  40. MaxIdleConns int `json:"maxIdleConns,optional"`
  41. }
  42. var (
  43. ConfigJson Config
  44. )
  45. type Mysql struct {
  46. DbName string `json:"dbName"`
  47. Address string `json:"address"`
  48. UserName string `json:"userName"`
  49. PassWord string `json:"passWord"`
  50. MaxOpenConns int `json:"maxOpenConns"`
  51. MaxIdleConns int `json:"maxIdleConns"`
  52. }
  53. func init() {
  54. conf.MustLoad("etc/usercenter.yaml", &ConfigJson)
  55. //初始化资源中台相关
  56. resourceClient := zrpc.MustNewClient(zrpc.RpcClientConf{
  57. Etcd: discov.EtcdConf{
  58. Hosts: ConfigJson.ResourceEtcdConf.Etcd.Hosts,
  59. Key: ConfigJson.ResourceEtcdConf.Etcd.Key,
  60. },
  61. })
  62. entity.ResourceLib = resource.NewResource(resourceClient)
  63. }