Two Newbie Questions - Sorry

I noticed that in two places I have coded what seems to be a label at the end of a defer func(filename) as seen below:

	defer func(oW *os.File) {
		err := oW.Close()
		if err != nil {
			fmt.Printf("Error: %v  ......)
			os.Exit(1)
		}
	}(oW)

My first question is: what is the (oW) at the end??? I wrote this piece of code a long time ago and I can find nothing when searching the defer func() - is this some kind of optional informational label I can put at the bottom of blocks??? If so what is it called or where is it in the syntax definition so I can know what I am doing?

Second Question: Perhaps this question is better put in a JetBrains forum as I am using goLand but since I am here: when I use the magnifying glass in the upper right hand corner I am not seeing references to the searched string in my code. I have moved to a new computer since I last used this and I think something is wrong in my configuration settings???

You are running the closure function func() {}() because defer should be a call.

The (oW) is literally an argument that you are passing to the function.

Lets say this function wasn’t anonymous:

func CloseFile(ow *os.File) {
		err := oW.Close()
		if err != nil {
			fmt.Printf("Error: %v  ......)
			os.Exit(1)
		}
}

This is how you call this function:

CloseFile(oW) // <- the (oW) at the end here is literally
//  for the same reason as in your example.

Answering the second question: make sure that “All” tab is selected
image

1 Like