Documentation
¶
Index ¶
- Variables
- func Exec(ctx context.Context, q Querier, sql string, args ...any) (pgconn.CommandTag, error)
- func GenerateRandomSecret(length int) (string, error)
- func HashToken(token string) string
- func QueryMany[T any](ctx context.Context, q Querier, sql string, args ...any) ([]T, error)
- func QueryOne[T any](ctx context.Context, q Querier, sql string, args ...any) (T, error)
- func WithTransaction(ctx context.Context, pool *pgxpool.Pool, fn func(Querier) error) error
- type Entity
- type OAuthAuthorizationCode
- type PasswordResetToken
- type Querier
- type Session
- type Store
- type User
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrDuplicateKey = errors.New("db.err.duplicate_key")
View Source
var ErrObjectNotFound = errors.New("db.err.object_not_found")
View Source
var ErrTooManyRows = errors.New("db.err.too_many_rows")
Functions ¶
func GenerateRandomSecret ¶
Types ¶
type OAuthAuthorizationCode ¶
type OAuthAuthorizationCode struct {
ID uuid.UUID `db:"id"`
CreatedAt time.Time `db:"created_at"`
Code string `db:"code"`
UserID uuid.UUID `db:"user_id"`
RedirectURI string `db:"redirect_uri"`
CodeChallenge string `db:"code_challenge"`
CodeChallengeMethod string `db:"code_challenge_method"`
ExpiresAt time.Time `db:"expires_at"`
UsedAt *time.Time `db:"used_at"`
}
func NewOAuthAuthorizationCode ¶
func NewOAuthAuthorizationCode(plainCode string, userID uuid.UUID, redirectURI, challenge, method string) *OAuthAuthorizationCode
type PasswordResetToken ¶
type PasswordResetToken struct {
ID uuid.UUID `db:"id"`
UserID uuid.UUID `db:"user_id"`
Token string `db:"token"`
CreatedAt time.Time `db:"created_at"`
ExpiresAt time.Time `db:"expires_at"`
UsedAt *time.Time `db:"used_at"`
}
func NewPasswordResetToken ¶
func NewPasswordResetToken(plainToken string, userID uuid.UUID) *PasswordResetToken
type Querier ¶
type Querier interface {
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}
Querier is satisfied by both *pgxpool.Pool and pgx.Tx, allowing the generic helpers below to be used inside transactions as well as outside them.
type Store ¶
type Store interface {
UserByEmail(ctx context.Context, email string) (*User, error)
User(ctx context.Context, id uuid.UUID) (*User, error)
CreateUser(ctx context.Context, user *User) (*User, error)
UpdateUserLastLogin(ctx context.Context, userID uuid.UUID, loginAt time.Time) error
CreateSession(ctx context.Context, session *Session) (*Session, error)
UserAndSessionBySessionID(ctx context.Context, sessionID uuid.UUID) (*User, *Session, error)
DeleteSession(ctx context.Context, sessionID uuid.UUID) error
CreateOAuthCode(ctx context.Context, code *OAuthAuthorizationCode) (*OAuthAuthorizationCode, error)
OAuthCodeByHash(ctx context.Context, codeHash string) (*OAuthAuthorizationCode, error)
ConsumeOAuthCode(ctx context.Context, codeID uuid.UUID, usedAt time.Time) error
CreatePasswordResetToken(ctx context.Context, token *PasswordResetToken) (*PasswordResetToken, error)
PasswordResetTokenByHash(ctx context.Context, hash string) (*PasswordResetToken, error)
ConsumePasswordResetToken(ctx context.Context, id uuid.UUID, usedAt time.Time) error
UpdateUserPassword(ctx context.Context, userID uuid.UUID, passwordHash string) error
}
type User ¶
type User struct {
Entity
Email string `json:"email" db:"email"`
IsEnabled bool `json:"is_enabled" db:"is_enabled"`
SecurityStamp uuid.UUID `json:"security_stamp" db:"security_stamp"`
LastLoginAt *time.Time `json:"last_login_at" db:"last_login_at"`
PasswordHash *string `json:"-" db:"password_hash"`
}
Click to show internal directories.
Click to hide internal directories.