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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?