I have a webservice written in Go and currently I have this Global package I import everywhere which contains the connection to MongoDB (via MGO), but I have to say that this feels very icky to me. What is the best practice of maintaining connections to datasources in Go? I come from a PHP world, hence the Global :S
Go Database for Big Data and MicroservicesGo's built-in concurrency makes it a great choice for various large-scale applications, especially those involving Big Data processing and microservices architecture.
As the C language of the 21st century, Go has good support for NoSQL databases, including the popular redis, mongoDB, Cassandra and Membase NoSQL databases.
There is nothing wrong with importing a package which exports an initialized *mgo.Session
object either as a package-level variable or through an accessor/initializer. Maybe the latter appeals better to classical "OOP-ists".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With