Documentation ¶
Index ¶
- Constants
- Variables
- func CipherDecrypt(encrypted []byte) ([]byte, error)
- func CipherEncrypt(plain []byte) (string, error)
- func Close(err error)
- func DeleteFile(path, name string) error
- 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 RandomString(length int) 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(v any) error
- func UpdateSettings(confmap map[string]any) error
- type Ban
- type FileInfo
- type KVTable
- type LimiterStat
- type MDB
Constants ¶
const ( URIOptimizations = "" /* 199-byte string literal not displayed */ BackupPath = "sqlite/backup" )
URIOptimizations for other SQLite3 drivers.
Variables ¶
var ( LimiterBanCount int LimiterBurst int LimiterRate int )
Functions ¶
func CipherDecrypt ¶
func CipherEncrypt ¶
func DeleteFile ¶
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 RandomString ¶
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 Ban ¶
type Ban struct { IP string `mold:"trim" validate:"required,ip"` Date int64 Reason string `mold:"trim" validate:"required"` }
func GetAllBans ¶
type FileInfo ¶
func CreateBackup ¶
Backup Sqlite3 database to a file.
type LimiterStat ¶
func LimitersStats ¶
func LimitersStats(ignore string) []LimiterStat