dpowhyh70416 2016-07-18 14:28
浏览 52
已采纳

可以使用特定Go版本的Golang构建标签吗? [重复]

This question already has an answer here:

Using build tags alone is it possible to target a particular Go version in a file?

// +build go1.7

eg. with the adding of golang.org/x/net/context to the standard lib, I have some code that I want to update to use the std lib context ( when it's released ) but be able to maintain backward compatibility for those that have not yet updated.

I know there are many ways to control this including the branch name and go get, just wondering if there's a way using build tags.

Thanks in Advance.

</div>
  • 写回答

1条回答 默认 最新

  • drtpbx3606 2016-07-18 14:57
    关注

    Put the code that depends on contexts in a file with the following build tag. This code is compiled for Go 1.7 and onward.

    // +build go1.7
    

    Put the backwards compatibility code in a file with the following build tag. This code is used for all versions of Go before 1.7.

    // +build !go1.7
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?