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...

The standard lib package, database/sql, provides the Open function to initialize the connection to the database with the driver name and connection details (connection URL in this case). Note that the Open function does not create the connection immediately, and may only validate the parameters passed to the function.

The connection to the database could be verified by the Ping method, which is available in the returned DB struct pointer.

The driver itself is initialized in the init function of the driver package. The driver registers itself with the driver name by the Register function of the sql package. The github.com/lib/pq driver registers itself as postgres.

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