package admin import ( "fmt" "os" "strings" "time" "gd_admin/common.in/clinit" "gd_admin/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() projectName := cfg.Section("").Key("project_name").String() // 先行于读配置 clinit.InitEtcd(etcdAddrs) conf := config.GetConfig(projectName+"/"+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.Admin.Name, etcdAddrs, nil) xcli = client.NewXClient(conf.Rpc.Admin.Name, client.Failtry, client.RandomSelect, d, opt) }