func main() {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"127.0.0.1:2379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		// handle error!
		fmt.Printf("connect to etcd failed, err:%v\n", err)
		return
	}
	fmt.Println("connect to etcd success")
	defer cli.Close()
	// put
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	//str:=`[{"path":"d:\\logs\\test.log","topic":"s4_log"},{"path":"f:\\logs\\web.log","topic":"web_log"}]`
	str:=`[{"path":"d:\\logs\\test.log","topic":"s4_log"},{"path":"f:\\logs\\web.log","topic":"web_log"},{"path":"c:\\logs\\lb.log","topic":"lb_log"},{"path":"c:\\logs\\lb2.log","topic":"test_log"}]`
	_, err = cli.Put(ctx, "collect_log_conf", str)
	cancel()
	if err != nil {
		fmt.Printf("put to etcd failed, err:%v\n", err)
		return
	}
	// get
	ctx, cancel = context.WithTimeout(context.Background(), time.Second)
	resp, err := cli.Get(ctx, "collect_log_conf")
	cancel()
	if err != nil {
		fmt.Printf("get from etcd failed, err:%v\n", err)
		return
	}
	for _, ev := range resp.Kvs {
		fmt.Printf("%s:%s\n", ev.Key, ev.Value)
	}
}

1、创建初始化etcd配置,链接etcd服务器ip和端口;

2、使用context设置连接等待时间;

3、使用etcd的函数put()设置键值对,其中存放的值是json格式,并且保存的是日志读取的文件夹;

4、使用get()得到键值对中的值,后期可在kafka分布式子系统中调用,得到日志路径和主题等配置信息。