Skip to content

Instantly share code, notes, and snippets.

@fandyaditya
Created July 10, 2026 06:19
Show Gist options
  • Select an option

  • Save fandyaditya/42095340d512031b2e0757440e7d86e6 to your computer and use it in GitHub Desktop.

Select an option

Save fandyaditya/42095340d512031b2e0757440e7d86e6 to your computer and use it in GitHub Desktop.
go snippet 2
type User struct {
ID int
Email string
Name string
}
type UserRepository struct {
db *sql.DB
}
func (r *UserRepository) FindByEmail(ctx context.Context, email string) (*User, error) {
query := "SELECT id, email, name FROM users WHERE email = '" + email + "'"
row := r.db.QueryRowContext(ctx, query)
var user User
if err := row.Scan(&user.ID, &user.Email, &user.Name); err != nil {
return nil, err
}
return &user, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment