Forrest logo
back to the gofmt tool

gofmt:tldr:2d8f1

gofmt: Format a file, overwriting the original file in-place.
$ gofmt -w ${source-go}
try on your machine

The gofmt command is a tool in the Go programming language that is used to format Go source code according to a specified style guide.

The -w flag is an option provided by gofmt which stands for "write result to (source) file instead of stdout". When used, it will modify the specified Go source code file directly, applying the formatting changes.

source-go is a placeholder referring to the file name or the path of the Go source code file that you want to format using gofmt. The actual file name or path should replace ${source-go} in the command.

So, the command gofmt -w ${source-go} instructs the gofmt tool to format the specified Go source code file and overwrite it with the formatted version.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the gofmt tool