how do I use my import package's struct as a type in go

go

Solution

You must use a qualifier for imported entities - the package name from where the 'name' comes from:

func read(db *sql.DB, table string)

Problem

I'm working in a project and using "database/sql" package in go. And I want to use struct "DB" that declare in package "database/sql" as an argument to my func, so I can use the return value by sql.Open() and as my func's argument. Was it possible? Codes are below: ``` package main import ( "database/sql" "fmt" _ "github.com/Go-SQL-Driver/MySQL" ) func main() { var table string = "tablename" db, err := sql.Open("mysql", "user:password@/dbname") // read data from database read(db, table) } func read(db *DB, table string) { // read } ``` This code throws a "undefined: DB" error.

Original source