package order import ( "fmt" "os" "strings" "time" "gd_vehicle/common.in/clinit" "gd_vehicle/common.in/config" "github.com/smallnest/rpcx/client" "github.com/smallnest/rpcx/protocol" "github.com/smallnest/rpcx/share" ini "gopkg.in/ini.v1" ) var xcli client.XClient func init() { cfg, err := ini.Load("../../conf/app.conf") if err != nil { fmt.Printf("Fail to read file: %v\n\n", err) os.Exit(1) } runmode := cfg.Section("").Key("runmode").String() etcdAddrs := strings.Split(cfg.Section("").Key("etcd_addrs").String(), ",") encryptKey := cfg.Section("").Key("encrypt_key").String() // 先行于读配置 clinit.InitEtcd(etcdAddrs) conf := config.GetConfig("/gd/"+runmode, encryptKey, clinit.GetEtcdClient()) if conf == nil { fmt.Printf("get conf failed\n\n") os.Exit(1) } opt := client.Option{ Retries: 1, RPCPath: share.DefaultRPCPath, ConnectTimeout: 10 * time.Second, SerializeType: protocol.JSON, CompressType: protocol.None, BackupLatency: 10 * time.Millisecond, } d := client.NewEtcdDiscovery(conf.Rpc.BasePath, conf.Rpc.Vehicle.Name, etcdAddrs, nil) xcli = client.NewXClient(conf.Rpc.Vehicle.Name, client.Failtry, client.RandomSelect, d, opt) }