123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package vehicle
- 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"
- "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.Vehicle.Name, etcdAddrs, nil)
- xcli = client.NewXClient(conf.Rpc.Vehicle.Name, client.Failtry, client.RandomSelect, d, opt)
- }
|