goland how to use gofmt?

Mikita Melnikau picture Mikita Melnikau · Dec 10, 2017 · Viewed 42k times · Source

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?

Answer

negi Yogi picture negi Yogi · Dec 10, 2017

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.