这是一种实现方法-只需在
Scan函数中手动分配所有结构值即可。
func getUser(name string) (*User, error) { var u User // this calls sql.Open, etc. db := getConnection() // note the below syntax only works for postgres err := db.QueryRow("SELECt * FROM users WHERe name = $1", name).Scan(&u.Id, &u.Name, &u.Score) if err != nil { return &User{}, err } else { return &u, nil }}


