Documentation ¶
Index ¶
- Constants
- Variables
- func Close(err error)
- func CookieHash(userInfo any, fingerprint, pepper []byte) (string, error)
- func CookieInfo(cookie string, user any)
- func CookieVerify(cookie string, fingerprint, pepper []byte) bool
- func DecodeString(data string) []byte
- func DeleteBackup(name string) error
- func DeleteUser(email string) error
- func EncodeBytes(bdata []byte) string
- func ExecSQLite(cmd string) [][]string
- func FilterSQL(sql string) []string
- func GetUserVersion() (int, error)
- func GoRangeWait[E any](list []E, gofunc func(int, E) error) []error
- func KVDel(t KVTable, key string) error
- func KVGet(t KVTable, key string) (string, error)
- func KVGetAll(t KVTable) (map[string]string, error)
- func KVHDel(t KVTable, key string, fields ...string) error
- func KVHGet(t KVTable, key string, fields ...string) (map[string]string, error)
- func KVHSet(t KVTable, key string, kvs map[string]any) error
- func KVLExist(t KVTable, key, value string) (bool, error)
- func KVLGet(t KVTable, key string) ([]string, error)
- func KVLPop(t KVTable, key string, end bool) (string, error)
- func KVLPush(t KVTable, key, field string, end bool) error
- func KVSDel(t KVTable, key string, values ...string) error
- func KVSSet(t KVTable, key string, values ...string) error
- func KVSet(t KVTable, kvs map[string]any) error
- func LimitersDelete(ip string)
- func LimitersLoadStore(ip string) *bLimiter
- func LimitersStore(ip string, ban bool)
- func Log(next http.Handler) http.Handler
- func Migrate(path string) error
- func NewLimiter(ban bool) *bLimiter
- func PasswordHash(key string) (string, error)
- func PasswordVerify(key, hash string) (bool, *argon2id.Params, error)
- func QuerySQLite(cmd string, noCalc bool) [][]string
- func RateLimiter(next http.Handler) http.Handler
- func ReadMigrations(path string) ([]string, error)
- func RemoveBan(ip string) error
- func RowsScan(rows *sql.Rows, dest any) error
- func RunSQLite(sql string) [][][]string
- func SendHTMLEmail(subject, html string, to ...string) error
- func Setup(newDB *sql.DB) error
- func SplitIntoMap(s, sep string) map[string]string
- func Transaction(execs ...string) error
- func Transform(r *http.Request, v any) error
- func UpdateSettings(confmap map[string]any) error
- func ValidPEM(certFile, keyFile string) bool
- type BackupInfo
- type Ban
- type KVTable
- type MDB
- type User
Constants ¶
const (
URIOptimizations = "" /* 199-byte string literal not displayed */
)
URIOptimizations for other SQLite3 drivers.
Variables ¶
Functions ¶
func CookieHash ¶
CookieHash generates a hash from a string and pepper.
func CookieVerify ¶
CookieVerify verifies a cookie hash with a pepper.
func DecodeString ¶
DecodeString decodes a string to a byte slice using Base64URL.
func DeleteBackup ¶
func DeleteUser ¶
func EncodeBytes ¶
EncodeBytes encodes a byte slice to a string using Base64URL.
func ExecSQLite ¶
execSQLite executes a given SQL command and returns the results in a 2D string slice. The result slice contains information about the execution, such as errors, rows affected, and last insert ID.
func FilterSQL ¶
Remove leading/trailing whitespace/comments and split the SQL string into individual commands.
func GetUserVersion ¶
Retrieves the user_version PRAGMA from the database and returns it as an integer. The user_version is used to track the current version of the database schema.
func GoRangeWait ¶
GoRangeWait is a concurrent function that waits at the end. It will run the gofunc for each element in the list concurrently. This is suitable for mutexed operations in gofunc.
func KVDel ¶
DELETES ROW FROM TABLE. Only this function will delete the row from the table. All other functions will empty the value field.
func KVHGet ¶
Retrieves the values of fields from a hash in a given table. If no fields are specified, all fields are returned.
func LimitersDelete ¶
func LimitersDelete(ip string)
func LimitersLoadStore ¶
func LimitersLoadStore(ip string) *bLimiter
func LimitersStore ¶
func Migrate ¶
Uses ReadMigrate to read the commands from the SQL file and applies them to the database.
func NewLimiter ¶
func NewLimiter(ban bool) *bLimiter
func PasswordHash ¶
Hard to crack password hashing with Argon2id.
func PasswordVerify ¶
PasswordVerify checks if a key matches a hash.
func QuerySQLite ¶
Executes a given SQL query and returns the results in a 2D string slice. The result slice contains the query results, including column headers and data rows. If noCalc is true, the column headers will not include the database type.
func ReadMigrations ¶
Reads a SQL file containing multiple migration commands and returns a map of versioned SQL strings.
func RunSQLite ¶
Take any string and attempt to execute it as a SQLite command. Returns a 3D array of strings with the result of the command.
func SendHTMLEmail ¶
SendEmail sends an email using the provided recipient with HTML content.
func Setup ¶
Connects to the SQLite3 database and sets the global DB variable. nil defaults to ncruces SQLite3 driver.
func SplitIntoMap ¶
Helper function to split a string into a map of key-value pairs.
func Transaction ¶
Executes a series of SQL commands within a single transaction.
func UpdateSettings ¶
Updates the settings table with the given key-value pairs. Update Settings map with the new values.
Types ¶
type BackupInfo ¶
func CreateBackup ¶
func CreateBackup(name string) (*BackupInfo, error)
Backup Sqlite3 database to a file.
func GetBackup ¶
func GetBackup(name string) (*BackupInfo, error)
func ListBackups ¶
func ListBackups() ([]*BackupInfo, error)
type Ban ¶
type Ban struct { IP string `mold:"trim" validate:"required,ip"` Date int64 Reason string `mold:"trim" validate:"required"` }
func GetAllBans ¶
type User ¶
type User struct { ID int64 Email string `mold:"trim" validate:"required,email"` Role string `mold:"trim" validate:"omitempty"` Password string `mold:"trim" validate:"omitempty,min=12"` Updated int64 Created int64 }