Is there a command line tool in Golang to only check syntax of my source code?
You can use gofmt
to check for syntax errors without actually building the project.
gofmt -e my_file.go > /dev/null
You can later use $? bash variable, return code 0 implies success, 2 means syntax check. /dev/null will eat the code, but the errors go to stderr
The -e
option is defined as:
report all errors (not just the first 10 on different lines)
gofmt --help usage: gofmt [flags] [path ...] -comments=true: print comments -cpuprofile="": write cpu profile to this file -d=false: display diffs instead of rewriting files -e=false: report all errors (not just the first 10 on different lines) -l=false: list files whose formatting differs from gofmt's -r="": rewrite rule (e.g., 'a[b:len(a)] -> a[b:]') -s=false: simplify code -tabs=true: indent with tabs -tabwidth=8: tab width -w=false: write result to (source) file instead of stdout
Is there much point only checking the syntax? The Go compiler is so fast you might as well compile everything too.
In this sense, the underlying mental model is quite different from that of Ruby.
Just use go build
or go install
. http://golang.org/cmd/go/