|
@@ -8,7 +8,9 @@ import (
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
"github.com/go-xorm/xorm"
|
|
|
+ clientv3 "go.etcd.io/etcd/client/v3"
|
|
|
"log"
|
|
|
+ "time"
|
|
|
|
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
|
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/internal/server"
|
|
@@ -22,6 +24,7 @@ import (
|
|
|
)
|
|
|
|
|
|
var configFile = flag.String("f", "etc/message.yaml", "the config file")
|
|
|
+var EtcdCli *clientv3.Client
|
|
|
|
|
|
func main() {
|
|
|
flag.Parse()
|
|
@@ -39,6 +42,7 @@ func main() {
|
|
|
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
|
|
s.Start()
|
|
|
}
|
|
|
+
|
|
|
//创建orm引擎
|
|
|
func init() {
|
|
|
conf.MustLoad(*configFile, &config.ConfigJson)
|
|
@@ -50,5 +54,17 @@ func init() {
|
|
|
if err != nil {
|
|
|
log.Fatal("数据库连接失败:", err)
|
|
|
}
|
|
|
- fmt.Println(config.ConfigJson.DataSource+"链接成功")
|
|
|
+ fmt.Println(config.ConfigJson.DataSource + "链接成功")
|
|
|
+
|
|
|
+ //var err error
|
|
|
+ EtcdCli, err = clientv3.New(clientv3.Config{
|
|
|
+ Endpoints: config.ConfigJson.Etcd.Hosts,
|
|
|
+ DialTimeout: 5 * time.Second,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ // handle error!
|
|
|
+ log.Printf("connect to etcd failed, err:%v\n", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ log.Println("connect to etcd success")
|
|
|
}
|