Tom Elliott
Tom Elliott

Reputation: 1926

Is there a way to stop go code compiling with older versions of go?

We have some internal command line tools written in Go, and we're using the vendor folder to control their dependencies.

However, if the tools are updated with go get using Go 1.4 or lower (or 1.5 without the vendor experiment flag), from what I understand the dependencies will be pulled separately into the gopath.

Is there a way to require a minimum version of the go compiler to compile a package, so we have a hard and fast way to ensure everyone has the minimum version we expect?

Upvotes: 3

Views: 678

Answers (1)

Nick Craig-Wood
Nick Craig-Wood

Reputation: 54117

We do this in rclone with a build constraint like this. All go compilers version >= 1.5 will set the go1.5 build constraint so this won't build with a compiler < 1.5 and will build with a compiler >= 1.5.

//+build !go1.5

package main

// Upgrade to Go version 1.5 to compile rclone.
func init() { Go_version_1_5_required_for_compilation() }

Upvotes: 3

Related Questions