Once we run the program, the HTTP server will start locally listening on port 8080.
Browsing to http://localhost:8080/ will return you the current database name, as shown in the following screenshot:
Let’s understand the program we have written:
- Using import ( "database/sql" "fmt" "log" "net/http" _ "github.com/go-sql-driver/mysql"), we imported github.com/go-sql-driver/mysql for its side effects or initialization, using the underscore in front of an import statement explicitly.
- Using var db *sql.DB, we declared a private DB instance.