init.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package provider
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. "gd_management/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. // 先行于读配置
  14. //clinit.InitEtcd(etcdAddrs)
  15. conf := config.GetConfigForK8s()
  16. if conf == nil {
  17. fmt.Printf("get conf failed\n\n")
  18. os.Exit(1)
  19. }
  20. /*opt := client.Option{
  21. Retries: 1,
  22. RPCPath: share.DefaultRPCPath,
  23. ConnectTimeout: 10 * time.Second,
  24. SerializeType: protocol.JSON,
  25. CompressType: protocol.None,
  26. BackupLatency: 10 * time.Millisecond,
  27. }
  28. d := client.NewEtcdDiscovery(conf.Rpc.BasePath, conf.Rpc.Management.Name, etcdAddrs, nil)
  29. xcli = client.NewXClient(conf.Rpc.Management.Name, client.Failtry, client.RandomSelect, d, opt)
  30. */
  31. opt := client.Option{
  32. Retries: 1,
  33. RPCPath: share.DefaultRPCPath,
  34. ConnectTimeout: 10 * time.Second,
  35. SerializeType: protocol.JSON,
  36. CompressType: protocol.None,
  37. BackupLatency: 10 * time.Millisecond,
  38. }
  39. sd := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%s", conf.Rpc.Management.ServiceName, conf.Rpc.Management.ServicePort.String()), "")
  40. xcli = client.NewXClient(conf.Rpc.Management.Name, client.Failtry, client.RandomSelect, sd, opt)
  41. }