Documentation
¶
Index ¶
- Constants
- Variables
- func BasicHash(plain ...[]byte) string
- 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 LimitersDelete(ip string)
- func LimitersLoadStore(ip string) *bLimiter
- func LimitersStore(ip string, ban bool)
- 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 ReadMigrations(path string) ([]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 StructMap(v any) map[string]string
- func Transaction(execs ...string) error
- func Transform(v any) error
- func UpdateSettings(confmap map[string]string) error
- func ValidateBool(setting string) error
- func ValidateInt(setting string) error
- type Ban
- type FileInfo
- type KVTable
- func (t *KVTable) DEL(key string) error
- func (t *KVTable) GET(key string) (string, error)
- func (t *KVTable) GETALL() (map[string]string, error)
- func (t *KVTable) GETALLSTRUCT(order string, v any) error
- func (t *KVTable) HDEL(key string, fields ...string) error
- func (t *KVTable) HGET(key string, fields ...string) (map[string]string, error)
- func (t *KVTable) HSET(key string, kvs map[string]string) error
- func (t *KVTable) LEXISTS(key, value string) (bool, error)
- func (t *KVTable) LGET(key string) ([]string, error)
- func (t *KVTable) LPOP(key string, end bool) (string, error)
- func (t *KVTable) LPUSH(key, field string, end bool) error
- func (t *KVTable) SDEL(key string, values ...string) error
- func (t *KVTable) SET(kvs map[string]string) error
- func (t *KVTable) SSET(key string, values ...string) error
- 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 )
var ( DB *MDB // DB is the global database connection. EmailAuth smtp.Auth // EmailAuth is the SMTP authentication. Settings = make(map[string]string) // Settings is a map of key-value pairs from the setting table. KVSetting = KVNew("setting", "Key", "Value") // KVSetting is the key-value setting table. )
Functions ¶
func CipherDecrypt ¶
Decrypts and decompresses data.
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 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 ¶
RandomString generates a random string of a given length.
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. Also initializes the crypto variables and loads the settings table.
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.
func ValidateBool ¶
ValidateBool checks if a string is a boolean.
func ValidateInt ¶
ValidateInt checks if a string is an integer.
Types ¶
type FileInfo ¶
func CreateBackup ¶
Backup Sqlite3 database to a file.
type KVTable ¶
func (*KVTable) DEL ¶
DELETES ROW FROM TABLE. Only this function will delete the row from the table. All other functions will empty the value field.
func (*KVTable) GETALL ¶
Retrieves all key-value pairs from a given table and returns them in a map. OPTIONS: ASC, DESC, or blank for no order.
func (*KVTable) GETALLSTRUCT ¶
Retrieves all key-value pairs from a given table and returns them in the provided STRUCT. OPTIONS: ASC, DESC, or blank for no order.
func (*KVTable) HGET ¶
Retrieves the values of fields from a hash in a given table. If no fields are specified, all fields are returned.
type LimiterStat ¶
func LimitersStats ¶
func LimitersStats(ignore string) []LimiterStat