Q:

Global variable private to file

In GOLANG, Is there a way to make a variable's scope local to a file within a package?
In my case, there are 2 files ex1.go and ex02.go. ex01.go defines a global variable
var wg sync.WaitGroup

which is used across functions in that file.
In another file ex02.go (which has no relation with ex01.go except that both ex01.go and ex02.go belong to the same class of problems - i.e. concurrency), I can't define a variable for waitGroup as
var wg sync.WaitGroup

I get an error - "variable name is re-declared in this block"
Is there a way to keep the variable names from spilling over to the other files?

A:

For the purpose of variable scoping, files have no meaning in Go. Think of all files in a package as if they would be concatenated, which (simplified) is exactly what happens before compilation.
That means: No, there is no way of scoping a variable to a file.
If you need two global WaitGroups, you need to define them as individual variables.

A:

Only explicitly imported identifiers have file's scope. Say in file wg.go you define
package wg
var Wg sync.WaitGroup
// and all staff common to class of problems - i.e. concurrency

and then you can in file ex1.go
import wg
wg.Wg.Add(1) //use locally to file

same in ex2.go

