Skip to content

Instantly share code, notes, and snippets.

@dmitshur
Last active May 1, 2016 03:15
Show Gist options
  • Save dmitshur/3f58c38dc262058c3e04 to your computer and use it in GitHub Desktop.
Save dmitshur/3f58c38dc262058c3e04 to your computer and use it in GitHub Desktop.

An example where var err error; something, err = foo() is nicer than something, err := foo().

This is a less common situation.

	fd := os.Stdout
	if *output != "" {
		var err error
		fd, err = os.Create(*output)
		if err != nil {
			log.Fatalf("cover: %s", err)
		}
	}
	fd.Write(initialComments(content)) // Retain '// +build' directives.

vs

	fd := os.Stdout
	if *output != "" {
		fd2, err := os.Create(*output)
		if err != nil {
			log.Fatalf("cover: %s", err)
		}
		fd = fd2
	}
	fd.Write(initialComments(content)) // Retain '// +build' directives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment