Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the "main redeclared" check in golint on Atom's go-plus package?

Tags:

I've just started learning go and am using Atom with the go-plus package for coding. As such, all my code resides in one folder with each file having its own func main.

Each time I save the code, the linter runs and gives the error main redeclared in this block. I understand that when I start using go in an actual project, I need to have only one main per folder, but right now, that isn't necessary. Having multiple folders with only one file in each is quite cumbersome.

Is there any way I can turn off the "main redeclared" option in the linter?

like image 978
sudhanva Avatar asked Feb 23 '18 09:02

sudhanva


2 Answers

I have the same problem, as you, I just started to learn Go language with Atom but after some research a found this link that could solve our problem.

https://github.com/lucasb-eyer/go-colorful/issues/5

The solution proposed is to add the underscore character "_" to your file name. In this way you will have a project folder structured like this:

Go workplace

  1. _example1.go
  2. example2.go

and Atom does not show error message main redeclared in this block, but to run by teminal the _example1.go you must delete the "_" and add it to example2.go, in this way you can run example1.go.

like image 76
Leonardo Avatar answered Sep 21 '22 05:09

Leonardo


If you are using terminal for running your one-file go programs, you can work with that error. Running go run example1.go will run your code without any error. Running go run example2.go will also run your other files without errors.

like image 21
atakanyenel Avatar answered Sep 19 '22 05:09

atakanyenel