This package is heavily inspired by jtolds' gls package.
I made my own version of jtolds' package because Brad Fitzpatrickcreated a function to get the current GoRoutine ID. Am I a horrible person for using this function? Probably.
Why is this useful?
So far, the only thing I'm using it for is storing a unique identifier for a given HTTP request so I can track its progress through my code via logging. I felt this approach was easier and less messy than refactoring every function to take some kind of context or identifier.
Cleanup removes all data associated with this goroutine. If this is not
called, the data may persist for the lifetime of your application. This
must be called from the very first goroutine to invoke Set
Go creates a new goroutine and runs the provided function in that new
goroutine. It also associates any key,value pairs stored for the parent
goroutine with the child goroutine. This function must be used if you wish
to preserve the reference to any data stored in gls. This function
automatically cleans up after itself. Do not call cleanup in the function
passed to this function.
With is a convenience function that stores the given values on this
goroutine, calls the provided function (which will have access to the
values) and then cleans up after itself.