go get github.com/outreach-golang/etcd
因为etcd和grpc本身的兼容性问题,所以需要添加某些包的替换
replace (
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.5
github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0
google.golang.org/grpc => google.golang.org/grpc v1.26.0
)
import "github.com/outreach-golang/etcd"
if err = etcd.GEtcd.InitEtcd(
//环境变量值(DefaultEV,TestingEV,ReleaseEV,ProductionEV)
etcd.EnvVar(etcd.DefaultEV),
//etcd地址
etcd.Points([]string{"127.0.0.1:2379"}),
); err != nil {
log.Fatal(err.Error())
}
支持SSL配置,可自行加相应配置项即可
etcdRegister := etcd.NewServiceRegister(etcd.GEtcd.GetCli())
if err = etcd.ServiceRegisterHandler.InitServiceRegister(
context.Background(),
etcdRegister,
"server.AppName",
"server.port"); err != nil {
log.Fatal(err.Error())
}