github.com/gaal/golf (go): Command golf provides some Go one-liner fun.  Invoke it with a snippet of Go code in the -e flag, which will be compiled and run for you.  Additional flags such as -n turn on awk/perl-like line mode, which are useful in processing text data. See the examples and flags sections below.  Some variables and functions are provided in the prelude package. These are inlined and made available to the one-liner. They are common elements of one-liner coding, for example the current line being processed in line mode.  Try these on your command line.  golf mimics perl's flags, but not perfectly so.  You can cluster one-letter flags, so -lane means the same as -l -a -n -e as it does in perl.  The -b and -E flags act as replacements for awk and Perl's BEGIN and END blocks. They are inserted before and after the -e snippet and only run once each. They are inserted in the same scope as the -e script, so variables declared in BEGIN are available for later blocks. -BEGIN and -END are aliases for -b and -E respectively.  -n puts golf in line mode: each command-line argument is treated as a filename, which is opened in succession. Its name will populate the Filename variable. Lines are then scanned, populating the Line variable. Stdin is read instead of a named file if no filenames were provided.  These do the same thing as the cat example above:  The File and Line labels can be continued/broken from to skip inputs.  -p implies -n and adds a "Print(Line)" call after each line. So you can even say:  -i causes edits to happen in-place: each input file is opened, unlinked, and the default output (Print, Printf) is sent to a new file with the original's name.  -I does the same, but keeps a backup of the original, according to the same renaming rules that perl -i uses:  Like perl, we do not support crossing filesystem boundaries in backups, nor do we create directories.  Unlike perl, in-place backup uses the -I flag, not the -i flag with an argument. Go's standard flag library does not support optional flags. So these don't act the same:  golf does not support a script mode (e.g., "golf FILE", or files with #!golf).  If you are writing a Go program in an editor, just go run it. If looking for convenience, see if package Prelude contains anything useful.
Keywords: go|one-liners