Documentation
¶
Overview ¶
Package `db` manages the user and roles database.
Index ¶
- type Ban
- type Database
- func (d *Database) AddAuth(username string, password string, role string) error
- func (d *Database) AddBan(ipid string, hdid string, reason string, moderator string, ...) error
- func (d *Database) CheckAuth(username string, password string) (ok bool, role string, err error)
- func (d *Database) CheckBanned(ipid string, hdid string) (bool, []Ban, error)
- func (d *Database) Close() error
- func (d *Database) GetBans(ipid string, hdid string) ([]Ban, error)
- func (d *Database) NullBan(id int) error
- func (d *Database) NullBans(ipid string, hdid string) error
- func (d *Database) RemoveAuth(username string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ban ¶
type Ban struct {
BanID int
IPID string
HDID string
Reason string
Moderator string
Start time.Time
End time.Time
}
Represents a ban in the database.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Represents a connection to the database. Used for database operations, goroutine-safe.
func Init ¶
Opens a connection to the database, creating it and initializing the tables if necessary.
func (*Database) AddBan ¶
func (d *Database) AddBan(ipid string, hdid string, reason string, moderator string, duration time.Duration) error
Adds a new ban to the database.
func (*Database) CheckAuth ¶
Checks whether a given username and password authenticate to a user. Returns whether the authentication was successful and the role the user has been authenticated to, along with an error should a DB error happen.
func (*Database) CheckBanned ¶
Verify if a given IPID and HDID is banned. If either are a match, returns a list of non-expired bans on this user.
func (*Database) GetBans ¶
Gets all bans that correspond to the passed IPID and HDID (including expired ones).
func (*Database) RemoveAuth ¶
Removes a user from the auth table.