I have written a simple code in Go but I am getting a weird error. I have attached a screenshot of code and error.
error: func main is unused
Code:
package structs
import "fmt"
func main() {
fmt.Println("Hello Structs")
}
Screenshot:

Change package structs to package main.
https://golang.org/ref/spec#Program_execution
A complete program is created by linking a single, unimported package called the main package with all the packages it imports, transitively. The main package must have package name
mainand declare a functionmainthat takes no arguments and returns no value.
Note that func main is unused by itself is not an error, it is just a report of an instance of unused code from the go-staticcheck linter. Unused functions are allowed by the Go compiler, but they will be, if I'm not mistaken, omitted from the output binary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With