Global variable private to file

Viewed 19830

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?

3 Answers
Related