I am trying to return all user information given ONE attribute which can either be user_id, email, or name.
u := User{
Email: "goda@go.com"
})
k := User {
Name: "john"
}
ReturnUserInfo(u)
ReturnUserInfo(k)
I invoke the function passing a User struct with only one field. Then I want to parse the field without EXPLICITLY saying the email. In the end I get the user information by passing an implicit field (user_id OR email etc.)
func ReturnUserInfo(u User) (y User){
// Retrieve first field from u and set them to field and value.
// NOT explicitly stating field := email, value := u.Email
db, _ := sql.Open("mysql", "root:password@/users")
_ := db.QueryRow("SELECT user_id, name, email FROM users WHERE ? = ?", field, value).Scan(
&u.User_id, &u.Name, &u.Email)
y = User{
User_id: u.User_id,
Name: u.Name,
Email: u.Email,
}
return y
}
I am not sure if I am able to do this in Golang, but I am creating this function so I do not have to explicitly tell Go to look for a particular attribute to return a user's information.