init.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package init
  2. import (
  3. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
  4. "flag"
  5. "fmt"
  6. _ "github.com/go-sql-driver/mysql"
  7. "github.com/zeromicro/go-zero/core/conf"
  8. "github.com/zeromicro/go-zero/core/discov"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. "github.com/zeromicro/go-zero/zrpc"
  11. "jyBXCore/entity"
  12. "jyBXCore/rpc/internal/config"
  13. )
  14. var configFile = flag.String("cf", "etc/bxcore.yaml", "the config file")
  15. var C config.Config
  16. var err error
  17. var dbFile = flag.String("df", "etc/db.yaml", "the db file")
  18. var DB config.Db
  19. var logFile = flag.String("lf", "etc/logs.yaml", "the logs file")
  20. var logc entity.Logc
  21. // 全文或附件搜索限制
  22. var SearchLimitKey = "jy_limitSearchText_new"
  23. var SearchLimitFlag = "jy_limitSearchText_%s"
  24. func init() {
  25. //基本配置
  26. conf.MustLoad(*configFile, &C)
  27. //数据库配置
  28. conf.MustLoad(*dbFile, &DB)
  29. //初始mongodb
  30. MongoDBInit(&DB.Mongo)
  31. //初始化msyql
  32. MysqlInit(&DB.Mysql)
  33. //初始redis
  34. RedisInit(&DB.Redis)
  35. //初始es
  36. EsInit(&DB.Es)
  37. //初始化日志信息
  38. conf.MustLoad(*logFile, &logc)
  39. if len(logc.Level) > 0 {
  40. for _, v := range logc.Level {
  41. logx.MustSetup(logx.LogConf{
  42. Mode: logc.Mode,
  43. Path: logc.Path,
  44. Level: v,
  45. KeepDays: logc.KeepDays,
  46. })
  47. logx.Info(v, "--日志记录")
  48. }
  49. }
  50. //初始化标签
  51. LabelInit()
  52. //
  53. SearchLimitKey = fmt.Sprintf(C.LimitSearchText.LimitKey, "jy_limitSearchText")
  54. //初始化权益中台相关
  55. powersClient := zrpc.MustNewClient(zrpc.RpcClientConf{
  56. Etcd: discov.EtcdConf{
  57. Hosts: C.PowersEtcdConf.Etcd.Hosts,
  58. Key: C.PowersEtcdConf.Etcd.Key,
  59. },
  60. })
  61. entity.PowerCheck = powercheck.NewPowerCheck(powersClient)
  62. }