Documentation ¶
Index ¶
- Variables
- func ApplyMigrations(dbURI string) error
- type AdminTable
- func (a *AdminTable) AddAdmin(ctx context.Context, user, pass string) error
- func (a *AdminTable) ChangePassword(ctx context.Context, user, pass string) error
- func (a *AdminTable) CheckPassword(ctx context.Context, user, pass string) (bool, error)
- func (a *AdminTable) DeleteAdmin(ctx context.Context, user string) error
- type FilterOption
- type PgxIface
- type User
- type UserTable
- func (t *UserTable) CreateUser(ctx context.Context, u *User) (int, error)
- func (t *UserTable) DeleteUser(ctx context.Context, id int) error
- func (t *UserTable) GetUser(ctx context.Context, id int) (*User, error)
- func (t *UserTable) GetUsers(ctx context.Context, opts ...FilterOption) ([]*User, error)
- func (t *UserTable) UpdateUser(ctx context.Context, u *User) error
Constants ¶
This section is empty.
Variables ¶
var ErrNoUser = errors.New("user not found")
ErrNoUser is returned by if the user or admin account is not found.
Functions ¶
func ApplyMigrations ¶
ApplyMigrations ensures all migrations are applied to the database at dbURI.
Types ¶
type AdminTable ¶
type AdminTable struct {
// contains filtered or unexported fields
}
AdminTable represents the table of admins permitted to use the service. It handles password hashing, so all `pass` method arguments are expected to be plaintext.
func NewAdminTable ¶
func NewAdminTable(l log.Logger, pool PgxIface) *AdminTable
NewAdminTable creates a new AdminTable backed by a Postgres connection pool.
func (*AdminTable) AddAdmin ¶
func (a *AdminTable) AddAdmin(ctx context.Context, user, pass string) error
AddAdmin creates a new admin account.
func (*AdminTable) ChangePassword ¶
func (a *AdminTable) ChangePassword(ctx context.Context, user, pass string) error
ChangePassword updates the hashed password for an admin. ErrNoUser is returned if the admin is not in the database.
func (*AdminTable) CheckPassword ¶
CheckPassword returns true if the admin exists and the password matches the hash on file. Otherwise it returns false.
func (*AdminTable) DeleteAdmin ¶
func (a *AdminTable) DeleteAdmin(ctx context.Context, user string) error
DeleteAdmin removes an admin account. It does not affect any changes they may have made to the data.
type FilterOption ¶
type FilterOption = func(f *filters)
FilterOption is a way to filter by particular values with GetUsers.
func WithKeyHash ¶
func WithKeyHash(keyHash string) FilterOption
WithKeyHash returns a FilterOption that filters by the provided MD5 key hash.
type PgxIface ¶
type PgxIface interface { Begin(context.Context) (pgx.Tx, error) Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error) QueryRow(context.Context, string, ...interface{}) pgx.Row Query(context.Context, string, ...interface{}) (pgx.Rows, error) Ping(context.Context) error Close() }
PgxIface allows the Table objects to use anything that looks like a *pgxpool.Pool.
type User ¶
type User struct { ID int `json:"id"` Name string `json:"name"` NameKeyHash string `json:"name_key_hash"` FinishYear int `json:"finish_year"` Professor bool `json:"professor"` TA bool `json:"ta"` StudentLeadership bool `json:"student_leadership"` AlumniBoard bool `json:"alumni_board"` }
User contains the information about a user necessary to admit them to the Discord server and assign appropriate roles upon entry to the server.
type UserTable ¶
type UserTable struct {
// contains filtered or unexported fields
}
UserTable represents the table of users that the bouncer will accept into the Discord server.
func NewUserTable ¶
NewUserTable creates a new UserTable backed by a Postgres connection pool.
func (*UserTable) CreateUser ¶
CreateUser creates a new user (ignoring the ID field) and returns the new ID.
func (*UserTable) DeleteUser ¶
DeleteUser removes the user by ID. If the user did not exist, returns ErrNoUser.
func (*UserTable) GetUser ¶
GetUser returns the user by ID, if present. If not present, ErrNoUser is returned.