lundi 31 octobre 2016

GoLang live connections in function

I had question about better code usage in golang.

What is the best case of usage live connection like database in few packages.

It is better to add database connection like

1.

func (database DB) getRows(){

}

or 2.

func getRows(database *DB){

}

or 3.

func getRows(){
  init database connection...
}

For 1 usage we need create local struct for DB

type DB struct{
connection
}

in different package I need move DB connection with creating local struct in each package or when some package did not use database connection but imported package use? How to send one configuration and create only one connection? Singleton is good idea?

Are you have any tips and trick for this case usage?

Aucun commentaire:

Enregistrer un commentaire