#How does side-effect imports works in go (lib/pq as example) ?

5 messages · Page 1 of 1 (latest)

north yoke
#

I am confused about how lib/pq functions gets called if we are just marking them as unused imports with _ I read about that and I saw it will call the init() function but that only calls sql.Register which modifies some global variable called drivers but then what ? where is the rest of the package code of lib/pq ?

buoyant field
#

in the objects it registered

north yoke
#

@buoyant field could u elaborate more on this ?

buoyant field
#

the library defines a driver, the driver contains all the "library code"

#

the library, in init, will register the driver