I have a web service written in Go, and currently I have this global package that I import everywhere that contains a connection to MongoDB (via MGO), but I have to say that it is very unpleasant for me. What is the best practice for maintaining data source connections in Go? I come from the world of PHP, so Global: S
There is nothing wrong with importing a package that exports an initialized object *mgo.Sessioneither as a package level variable or through an accessor / initializer. Maybe the latter appeals better to the classic OOP-Itzam.
*mgo.Session
Source: https://habr.com/ru/post/1538346/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1538341/how-to-push-2-items-to-an-array&usg=ALkJrhhbWFZ4KFtI9Q12Q7Q2yqq7KA2gtQEcho issue with while / if / else - phpSwipeRefreshLayout detects scroll down to start onRefresh () start - androidapplication.css and application.js net :: ERR_CONTENT_LENGTH_MISMATCH - ruby-on-railsHow to call Java class in Jsp - javaHow to combine two classes in one block? - listCreating a file entry - ruby | fooobar.comFunnel analysis using MongoDB? - javaUncaught TypeError: undefined is not a function - javascriptProblem with scrollbar with Kendo window - javascriptAll Articles