Skip to content

Golang: Two Fix for Declared and Not Used

Yes, Golang cares about how you declare and use the variable 🙂 If you declared a variable but have not used it in the code then the Go compiler will show you: declared but not used!

package main

func main() {
	myVariable := 1
}

Use it to make the Go compiler happy:

package main

import "fmt"

func main() {
	myVariable := 1

	fmt.Println(myVariable)
}

Or simply assign it to Blank Identifier _ (underscore):

package main

func main() {
	myVariable := 1

	_ = myVariable
}

Leave a Reply

Your email address will not be published. Required fields are marked *