Documentation
¶
Overview ¶
Package db provides functions for interacting with a database. Only MySQL database is supported for now.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MySQLDSNConfig ¶
MySQLDSNConfig is a simple util function for creating a mysql.Config with custom connection options.
Types ¶
type DBConnection ¶
type DBConnection interface {
// UserByUsername returns a UserDBEntity from database specified by the username
// parameter. If the username doesn't exist, error is returned.
UserByUsername(username string) (*UserDBEntity, error)
// SaveUser saves the UserModel passed as parameter to a database.
SaveUser(user *UserModel) error
// Save2FASecret saves secret for 2FA
Save2FASecret(username, secret string) error
// Get2FASecret retrieves 2FA secret
Get2FASecret(username string) (string, error)
UpdateEnabled2FA(username string, enabled bool) error
GetEnabled2FA(username string) (bool, error)
}
DBConnection represents a layer between the database and the application logic.
var DBConn DBConnection = nil
DBConnectino is a global connection to a database, through which application logic interacts with database.
type UserDBEntity ¶
type UserDBEntity struct {
// Uuid is a primary key of the UserDBEntity entry in database.
Uuid uuid.UUID
// Username of the user, must be unique.
Username string
// Email of the user, must be unique.
Email string
// Password hash of users account password.
PasswordHash string
// Secret2FA is used during 2FA
Secret2FA sql.NullString
// Enabled2FA indicates if user enabled 2FA
Enabled2FA bool
}
UserDBEntity is a model for how users are represented in database.
func (UserDBEntity) String ¶
func (u UserDBEntity) String() string
String returns string representation of a UserDBEntity.
Click to show internal directories.
Click to hide internal directories.