Monday, April 21, 2025
HomeGolangTwo Beginner Questions - Sorry - Getting Assist

Two Beginner Questions – Sorry – Getting Assist


I seen that in two locations I’ve coded what appears to be a label on the finish of a defer func(filename) as seen under:

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

My first query is: what’s the (oW) on the finish??? I wrote this piece of code a very long time in the past and I can discover nothing when looking out the defer func() – is that this some type of non-obligatory informational label I can put on the backside of blocks??? If that’s the case what’s it known as or the place is it within the syntax definition so I can know what I’m doing?

Second Query: Maybe this query is healthier put in a JetBrains discussion board as I’m utilizing goLand however since I’m right here: after I use the magnifying glass within the higher proper hand nook I’m not seeing references to the searched string in my code. I’ve moved to a brand new pc since I final used this and I feel one thing is unsuitable in my configuration settings???

You’re operating the closure operate func() {}() as a result of defer ought to be a name.

The (oW) is actually an argument that you’re passing to the operate.

Shall we say this operate wasn’t nameless:

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

That is the way you name this operate:

CloseFile(oW) // <- the (oW) on the finish right here is actually
//  for a similar motive as in your instance.

Answering the second query: guarantee that “All” tab is chosen
image

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments