1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import (
	"github.com/micro/go-micro/registry"
	"github.com/micro/go-plugins/registry/etcdv3"
	// other code ...
)

// other code ...

func main() {
	// etcdv3 registerDrive
	registerDrive := etcdv3.NewRegistry(func(options *registry.Options) {
		// etcd 地址
		options.Addrs = []string{"127.0.0.1:2379"}
		// etcd 用户名密码,如果设置的话
		etcdv3.Auth("root","password")(options)
	})
	service := micro.NewService(
		micro.Name(microName),
		micro.Registry(registerDrive),
	)

	// other code ...
}