In this example, we passed in flag to the underlying go tool link command that runs as a part of go build. This command uses double quotes around the contents passed to ldflags to avoid breaking characters in it, or characters that the command line might interpret as something other than what we want. From here, you could pass in many different link flags. For the purposes of this tutorial, we will use the -X flag to write information into the variable at link time, followed by the package path to the variable and its new value:
go build -ldflags="-X 'package_path.variable_name=new_value'"
To replace the Version variable in your example application, use the syntax in the last command block to pass in a new value and build the new binary:
go build -ldflags="-X 'main.Version=v1.0.0'"
As mentioned before, ldflags stands for linker flags, and is used to pass in flags to the underlying linker in the Go toolchain. This works according to the following syntax:
go build -ldflags="-flag"
Once your new app binary is built, run the application:
./app # Output: # OutputVersion: v1.0.0