init.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package vehicle
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. "gd_crontab/common.in/config"
  7. "github.com/smallnest/rpcx/client"
  8. "github.com/smallnest/rpcx/protocol"
  9. "github.com/smallnest/rpcx/share"
  10. )
  11. var xcli client.XClient
  12. func init() {
  13. /*cfg, err := ini.Load("../../conf/app.conf")
  14. if err != nil {
  15. fmt.Printf("Fail to read file: %v\n\n", err)
  16. os.Exit(1)
  17. }*/
  18. //runmode := cfg.Section("").Key("runmode").String()
  19. //etcdAddrs := strings.Split(cfg.Section("").Key("etcd_addrs").String(), ",")
  20. //encryptKey := cfg.Section("").Key("encrypt_key").String()
  21. //projectName := cfg.Section("").Key("project_name").String()
  22. // 先行于读配置
  23. conf := config.GetConfigForK8s()
  24. //conf := config.GetConfig(projectName+"/"+runmode, encryptKey, clinit.GetEtcdClient())
  25. if conf == nil {
  26. fmt.Printf("get conf failed\n\n")
  27. os.Exit(1)
  28. }
  29. opt := client.Option{
  30. Retries: 1,
  31. RPCPath: share.DefaultRPCPath,
  32. ConnectTimeout: 10 * time.Second,
  33. SerializeType: protocol.JSON,
  34. CompressType: protocol.None,
  35. BackupLatency: 10 * time.Millisecond,
  36. }
  37. d := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%s", conf.Rpc.Crontab.ServiceName, conf.Rpc.Crontab.ServicePort.String()), "")
  38. //d := client.NewEtcdDiscovery(conf.Rpc.BasePath, conf.Rpc.Crontab.Name, etcdAddrs, nil)
  39. xcli = client.NewXClient(conf.Rpc.Crontab.Name, client.Failtry, client.RandomSelect, d, opt)
  40. }