Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting an error in go: func main is unused

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:

enter image description here


1 Answers

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 main and declare a function main that 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.

like image 143
mkopriva Avatar answered Jan 01 '26 04:01

mkopriva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!