I know little about the “_” option for packages, but I use it (see below).
Turning _into an import path will import the package as usual (with its function init()), but it will not associate the name in your current package with the imported package.
, , - , SQL- RDBMS, RDBMS , RDBMS . , .
init() "github.com/go-sql-driver/mysql" :
func init() {
sql.Register("mysql", &MySQLDriver{})
}
database/sql Register , :
func Register(name string, driver driver.Driver)
:
, .
sql.Open:
func Open(driverName, dataSourceName string) (*DB, error)
, , , :
db, e := sql.Open("mysql", "user:pass@host:port")
, github.com/lxn/go-pgsql init() :
func init() {
sql.Register("postgres", sqlDriver{})
}
, , , .
flag :
./my_app -driver=mysql -db="user:pass@host:port"
sql.Open.