- From your Terminal/console application,createa new directory called~/projects/go-programming-cookbook/chapter4/global and navigate to this directory.
- Run the following command:
The apex and logrus packages in the earlier examples both used a package-level global variable. Sometimes, it's useful to structure your libraries to support both structures with a variety of methods and top-level functions so that you can use them directly without passing them around.
This recipe also demonstrates using sync.Once to ensure that the global logger will only be initialized once. It can also be bypassed by the Set method. The recipe only exports WithField and Debug, but you can imagine exporting every method attached to a log object.
How to do it...
These steps cover the writing and running of your application:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook...