Embarrassing Hello World problem

Hello I’ve recently started the StackSkills Go course with Todd M (can’t remember his surname atm). Every thing so far has gone fine, got WebStorm installed (on WIn 10) and just trying the first hello world example. The problem is that in the course video the line import “fmt” is automatically generated, when the fmt.Println line is completed, on my system the line is not generated. The GO plug-in has been installed, so what on earth am I missing. I feel like I need to get this sorted as I have clearly missed out something. Can anyone help?
Thanks in advance,
Carl

They’re probably using goimports, it’s a tool which formats code and inserts the correct imports for you (most of the time, it does guess and can make mistakes). You can set your editor to use it on save and magically see imports appear.

1 Like

Thanks for the reply. It’s strange because the video highlights the use of GO FMT to correct line spacing as a separate operation, whereas the automatic generation of the import “fmt” is presented as if it’s an “out of the box ready” feature, and the video quite clearly shows the newly generated line appearing as soon as the Println code completion option is selected. There’s nothing to suggest some clandestine use of GO IMPORT, though I haven’t discovered how to activate go import yet, so it may turn out to be intrinsically clandestine!

In practice I think most go developers nowadays use goimports as the formatter-on-save. It is go fmt with the addition of adding and removing package imports as needed. They probably considered it as something “out of the box” as they are used to it, and forgot to introduce it to new users.

Well I’ve installed goimports and quite frankly it has moved the progress of the project in a negative direction. Now, the line with fmt.Println shows fmt highlighted in red indicating an unresolved reference. Another thing which is weird and may be contributing to the problem is that despite me explicitly opening a location under my gocode path, the editor decided that I have opened a file location under appdata\local. Thus when I try to save it actually tries to carry out a save as, attempts to copy the file and then fails because another file is already there. This smacks to me of the editor trying to be too clever for its own good and falling down badly.

I’ve been in touch with Alexander Zolotov the author of the GO language plug in to WebStorm, IdeaJ etc. and he has set me right. Turns out that the automatic generation of the line does work “out of the box” - no need for goimports or any other such trickery. All that was missing was that a change I thought I’d made to the project SDK settings hadn’t registered properly, I had likely forgotten to press OK. And the other problem I had was due to me not setting up the project structure properly before attempting to use it. Anyhow, all is sorted now, thanks to all who replied.
Cheers,
Carl

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.