invites

package
v0.18.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package invites manages single-use invite codes for beta sign-up.

Codes are 20-character URL-safe random strings generated by the admin. Each code may be redeemed exactly once; Redeem uses an UPDATE...WHERE used_at IS NULL so concurrent redemption attempts leave only one winner.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCode = errors.New("invite code invalid or already used")

ErrInvalidCode is returned when a code does not exist or has already been redeemed.

Functions

This section is empty.

Types

type Code

type Code struct {
	Code      string
	CreatedAt time.Time
	UsedAt    *time.Time
	UsedBy    *string // email of the user who redeemed it, nil if unused
}

Code is the public view of an invite_codes row.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store wraps the invite_codes table.

func New

func New(db *sql.DB) *Store

New returns a Store backed by db.

func (*Store) Generate

func (s *Store) Generate(ctx context.Context, createdBy uuid.UUID, count int) ([]string, error)

Generate creates count single-use invite codes owned by createdBy and returns the plaintext code strings.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]Code, error)

List returns all invite codes, most-recently-created first. usedBy is the email of the redeeming user when known.

func (*Store) Redeem

func (s *Store) Redeem(ctx context.Context, code string, userID uuid.UUID) error

Redeem atomically marks code as used by userID. Returns ErrInvalidCode when the code was already redeemed or does not exist.

func (*Store) Validate

func (s *Store) Validate(ctx context.Context, code string) error

Validate checks that code exists and has not been redeemed. Returns ErrInvalidCode when it does not exist or is already used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL