I read all the decisions about dropping the ThreadLocal and I can relate.
Seems like passing around the request.Context() that is of type context.Context gives the ability to manage scoped services.
I am using logrus for logging and want to log a requestId that is a generate udid from a midlleware in gin
I know i can do something like this
func Authentication(conf Configuration, logger ILogger, cache ICacheService) gin.HandlerFunc {
return func(c *gin.Context) {
logger := logrus.WithContext(c)
c.Set("traceId", uuid.New().String())
c.Next()
}
}
And the pass around the entry or even store the entry inside the context whatever works, but...
I also have a Redis and MongoDb clients that are singletons and I am wrapping them with my own package to facilitate logging of any outgoing I\O requests.
because they are singletones I cannot pas the context.Context to the constructor but ill have to pass it to every method like GetKey SetKet etc..
any common patterns for using the context \ request id logging inside a Singleton service ?