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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失