Setting up goimports and gofmt in GoLand

When we write code in go, it is very likely to encounter some confusing errors such as “File is not goimports-ed (goimports)” or “File is not gofmted with s”. A way to solve this is to run command:
gofmt -s -w file.go and goimports -w file.go to format the code.

However, we have an easier way to set up in GoLand so that it will automatically run these two commands when we save file.go. Here’s how to set it up:

In such case, we will spare the effort to run these two commands every time.