func InitDB() *gorp.DbMap { //db, err := sql.Open("mssql", "server=127.0.0.1;user id=sa;password=sa;database=DB_DEMO;encrypt=disable") db, err := sql.Open("mysql", "root:root@/db_hygl?charset=utf8") checkErr(err, "sql.Open failed") // construct a gorp DbMap dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "utf8"}} //*kazarus:important dbmap.AddTableWithName(TUSER{}, "TBL_USER_GO") dbmap.AddTableWithName(TDICT{}, "TBL_DICT") var t *gorp.TableMap t = dbmap.AddTableWithName(TDICT{}, "TBL_DICT") fmt.Println(t.SqlForCreate(false)) fmt.Println(t.Columns[0].ColumnName) //create the table. in a production system you'd generally //use a migration tool, or create the tables via scripts //err = dbmap.CreateTablesIfNotExists() //checkErr(err, "Create tables failed") return dbmap }