码迷,mamicode.com
首页 > 其他好文 > 详细

go tags

时间:2019-07-16 08:27:23      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:zookeeper   port   官方文档   more   for   com   相同   条件   配置   

BuildTags

 
smallnest edited this page on 6 Feb 2018 · 3 revisions

为了避免引入不必要的库, rpcx采用了 Go 条件编译 的特性, 你可以只引入必要的特性。 比如你只使用 etcd 作为注册中心的时候, 你不希望引入 consul、zookeeper相关的库,你需要在 Go BuildTags中指定 etcd。

如果不指定 tags,可能会出现下面的错误。

.server.go:37:8: undefined: serverplugin.ConsulRegisterPlugin

Build Tags

build tag 也叫做 Build Constraints, Go文档中已经详细介绍了,不熟悉的同学应该先阅读一下官方文档,学习相关的基础知识。

Go 的工具文档中介绍了 tags参数:

-tags ‘tag list‘ a space-separated list of build tags to consider satisfied during the build. For more information about build tags, see the description of build constraints in the documentation for the go/build package.

也就是在使用下列命名的时候

go buildgo clean go getgo installgo listgo rungo test

加上 -tags "tag1 tag2 tag3" 参数。

比如:

go build -tags "reuseport quic kcp zookeeper etcd consul ping" .

rpcx支持的tags

  • reuseport
  • quic
  • kcp
  • zookeeper
  • etcd
  • consul
  • ping

IDE

主流的IDE都支持buildtags参数的设置,比如

  • goland
  • vscode
  • vim-go
  • sublime-go
  • atom

你需要把 -tags "reuseport quic kcp zookeeper etcd consul ping" 加入到IDE的配置中,否则会出现IDE无法识别对应的文件,即时文件真实存在,IDE也不识别这个文件。

IDE设置buildtags文件方式各不相同,你应该查找对应的IDE的设置方法进行设置。

go tags

标签:zookeeper   port   官方文档   more   for   com   相同   条件   配置   

原文地址:https://www.cnblogs.com/jackey2015/p/11192645.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!