Setting Go variables from the outside
CloudFlare's DNS server, RRDNS, is written in Go and the DNS team used to generate a file called version.go in our Makefile. version.go looked something like this:
// THIS FILE IS AUTOGENERATED BY THE MAKEFILE. DO NOT EDIT.
// +build make
package version
var (
Version = "2015.6.2-6-gfd7e2d1-dev"
BuildTime = "2015-06-16-0431 UTC"
)
and was used to embed version information in RRDNS. It was built inside the Makefile using sed and git describe from a template file. It worked, but was pretty ugly.
Today we noticed that another Go team at CloudFlare, the Data team, had a much smarter way to bake version numbers into binaries using the -X linker option.
The -X Go linker option, which you can set with -ldflags, sets the value of a string variable in the Go program being linked. You use it like this: -X main.version 1.0.0.
A simple example: let's say you have this source file saved as hello.go.
package main
import "fmt"
var who = "World"
func main() {
fmt.Printf("Hello, %s.n", who)
}
Then you can use go run (or other build commands like go build or go install Continue reading
A few weeks ago at AnsibleFest in NYC, we did something a little bit different: we assembled a panel of networking experts and had a very interesting discussion about some of the challenges and opportunities around networking automation. With representatives from Cisco, Cumulus, World Wide Technologies, and Network to Code, we dug into some of the reasons to automate your network, the technical and organizational challenges, and we reviewed some of the new Ansible modules being written for various networking components. Network automation is an exciting and early area for us, and we are looking forward to what the future holds.
DockerCon, Cisco Live, and ONS dominated June's coverage -- as did P4.