0

I've a package with global variables related to a file open (*os.File), and its logger associated. By another side, I'll build several commands that are going to use that package and I want not open the file to set it as logger every time I run a command.

So, the first program to run will set the global variables, and here is my question:

  • Do the next programs to use the package can access to those global variables without problem? It could be created a command with a flag to initialize those values before of be used by another programs, and another flag to finish it (unset the global variables in the package).

  • If that is not possible, which is the best option to avoid such IO-bound? To use a server in Unix sockets?

  • Are you talking about several *goroutines* accessing the global variables, or about several (independently startet) program instances = processes accessing the global variables? – Kissaki Jun 03 '12 at 17:20
  • I was talking about several program instances –  Jun 12 '12 at 20:53

1 Answers1

0

Assuming by 'program' you actually mean 'process', the answer is no.

If you want to share a (customized perhaps) logging functionality between processes then I would consider a daemon-like (Go doesn't yet AFAIK support writing true daemons) process/server and any kind of IPC you see handy.

zzzz
  • 87,403
  • 16
  • 175
  • 139
  • Read [this](http://stackoverflow.com/q/10067295/720999) for more info on how to daemonize processes written in Go. – kostix May 29 '12 at 14:23