I am currently working on Golang and struck at a point, related to package instantiation.
Issue: whether we can have different instances of the same package.
Problem Facing: While building a go packages, the utility packages(non main) are instantiated or compiled only once through out that particular building process. But while logging, I, for some purpose, want to have different loggers parallelly handling different package or files. Is there any way, that I can have multiple instances of the same package, so that changes made on each don't affect the other.
Note: I have found a good work around using go-logging library where I have declared multiple loggers and that quite satiates my need. So, my main question is whether we can have different instances of the same package.
Thanks to respond.
You can use Go modules and aliases to import two packages in the same source file. This is going to work when quote is a tagged repo or submodule.
import (
"rsc.io/quote"
quoteV3 "rsc.io/quote/v3"
)
func Hello() string {
return quote.Hello()
}
func Proverb() string {
return quoteV3.Concurrency()
}