Clarification on how to pass driver type and driver source to argument in function

How do I pass my driver type and driver source to a function that initialize a database connection using an ODBC adator.

Do I need the Driver struct for anything?
Can anybody please help in clarifying how and what to do to create a function that realize my aforementioned purpose.

import (
	"database/sql"
	_"github.com/alexbrainman/odbc"
)

type Driver struct {
	// Stats
	// contains filtered or unexported fields
}

func (d *Driver) InitialiseDBConnection(driverType, driverSourceName string) {
	db, err := sql.Open(driverType, driverSourceNam)

if err != nil {
		panic(err.Error())
	}
	err = db.Ping()
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()
	
}

Do I need a Driver Struct to contain a list of acceptable drivers or the underlined type of driver is passed from the function arguments?

Thanks

SQL driver packages have an init() that creates and registers the driver with the SQL package. You do not have to instantiate the driver yourself. The driver’s docs should tell you the registered name of the driver; if they don’t, you’ll have to print the sql.Drivers() output.

1 Like

Thanks for the clarification.