golang如何使用gofmt?

I started learning golang and installed GoLand from JetBrains. I am reading the book The Go Programming Language, and in the first chapter author strongly recommends using the gofmt tool before each save. How I can follow this recommendation in GoLand?

GoLand have commands to go fmt your file or project. Right click on your file and you will find it under "Go tools". You could see its shortcut there.

There are ways to format your code , you can do that by using any one of the way :

  1. once your code is done. just run the command " gofmt -s -w ." in terminal in required directory or else in needed file. it will format your whole directory/file as per your need .
  2. go to preferences ->Tools ->File Watchers and enable go fmt . This way on each save it will format the file.

Just want to add 1 more option. You can automatically apply go fmt every time when you are about to commit to git. When you open the commit window, under the Before Commit section, there is a Go fmt checkbox. Just check it. Later when you do another commit, the default value for that checkbox is checked. So, you only need to check it once. Then go fmt will run automatically before you commit.