Created
July 10, 2026 06:19
-
-
Save fandyaditya/42095340d512031b2e0757440e7d86e6 to your computer and use it in GitHub Desktop.
go snippet 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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