go语言使用etcd

package main

import (
    "fmt"
    "github.com/astaxie/beego/logs"
    etcd_client "github.com/coreos/etcd/clientv3"
)

type EtcdClient struct {
    client *etcd_client.Client
}

// 定义全局变量
var (
    etcdClient *EtcdClient 
)


func initEtcd(addr string) error {
    cli, err := etcd_client.New(etcd_client.Config{
        EndPoints: []string{"localhost:2379", "localhost:22379"},
        DialTimeout: 5 * time.Second,
    })

    if err != nil {
        logs.Error("connect etcd failed, err:", err)
        return
    }

    etcdClient = &EtcdClient{
        client: cli    
    }
    fmt.Println("connect success!")
}

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐