如何使用重写规则在gofmt工具中用空格替换制表符?

gofmt command supports -r flag to use rewrite rule during formatting the code. How to use it to replace tabs indentation with the spaces indentation?

Command gofmt

The rewrite rule specified with the -r flag must be a string of the form:

pattern -> replacement

Both pattern and replacement must be valid Go expressions.

The tab and space characters are not valid Go expressions. It won't work.

The Go Programming Language

Alan A. A. Donovan & Brian W. Kernighan

ISBN: 978-0134190440

gopl.io

Go takes a strong stance on code formatting. The gofmt tool rewrites code into the standard format, and the go tool’s fmt subcommand applies gofmt to all the files in the specified package, or the ones in the current directory by default. All Go source files in the book have been run through gofmt, and you should get into the habit of doing the same for your own code. Declaring a standard format by fiat eliminates a lot of pointless debate about trivia and, more importantly, enables a variety of automated source code transformations that would be infeasible if arbitrary formatting were allowed.

Always use gofmt code formatting.

Go's format forced by gofmt dictates to use tab indentation. Also see the decision lead to it: https://code.google.com/p/go/issues/detail?id=7101