O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

As mentioned in the previous recipe, Connecting the database, the Open function may just verify the connection details, but it is not mandatory to connect the database immediately. The actual connection to the database is usually lazy loaded and it is created by the first execution of statement against the database.

The pointer to the DB structure provides the Ping method, which usually does an idempotent call to the database. The variation to the Ping method is PingContext, which just adds the ability to cancel or time out the database call. Note that if the Ping function fails, the connection is removed from the database pool.

The pointer to the DB  struct also provides the method Conn to retrieve the connection from the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required