Documentation ¶
Index ¶
- Constants
- func ValidateDatabaseKey(key DatabaseKey) error
- func ValidateDatabaseName(name string) error
- type Database
- func (db *Database) DeleteAllKeys()
- func (db *Database) DeleteHashMapFields(key DatabaseKey, fields []string) (uint32, bool)
- func (db *Database) DeleteKey(key DatabaseKey) bool
- func (db *Database) GetAllHashMapFieldsAndValues(key DatabaseKey) (map[string]string, bool)
- func (db *Database) GetHashMapFieldValue(key DatabaseKey, field string) (string, bool)
- func (db *Database) GetKeyCount() uint32
- func (db *Database) GetKeys() []string
- func (db *Database) GetName() string
- func (db *Database) GetStoredSizeBytes() uint64
- func (db *Database) GetString(key DatabaseKey) (DatabaseStringValue, bool)
- func (db *Database) GetTypeOfKey(key DatabaseKey) (string, bool)
- func (db *Database) SetHashMap(key DatabaseKey, fields map[string]string)
- func (db *Database) SetString(key DatabaseKey, value DatabaseStringValue)
- type DatabaseKey
- type DatabaseStringValue
- type DefaultLogger
- func (l *DefaultLogger) ClearFlags()
- func (l *DefaultLogger) CloseLogFile() error
- func (l *DefaultLogger) Debug(v ...any)
- func (l *DefaultLogger) Debugf(format string, v ...any)
- func (l *DefaultLogger) Disable()
- func (l *DefaultLogger) EnableDebug()
- func (l *DefaultLogger) EnableLogFile(filePath string) error
- func (l *DefaultLogger) Error(v ...any)
- func (l *DefaultLogger) Errorf(format string, v ...any)
- func (l *DefaultLogger) Fatal(v ...any)
- func (l *DefaultLogger) Fatalf(format string, v ...any)
- func (l *DefaultLogger) Info(v ...any)
- func (l *DefaultLogger) Infof(format string, v ...any)
- func (l *DefaultLogger) Warning(v ...any)
- func (l *DefaultLogger) Warningf(format string, v ...any)
- type Logger
Constants ¶
const ( // DbNameMaxSize is the maximum length of a database name in bytes. DbNameMaxSize int = 64 // DbKeyMaxSize is the maximum length of a database key in bytes. DbKeyMaxSize int = 1024 )
Variables ¶
This section is empty.
Functions ¶
func ValidateDatabaseKey ¶ added in v0.7.1
func ValidateDatabaseKey(key DatabaseKey) error
ValidateDatabaseKey validates database key. Returns error if validation error is matched.
func ValidateDatabaseName ¶ added in v0.7.1
ValidateDatabaseName validates database name. Returns error if validation error is matched.
Types ¶
type Database ¶
type Database struct { // The name of the database. Name string // UTC timestamp describing when the database was created. CreatedAt time.Time // UTC timestamp describing when the database was updated. UpdatedAt time.Time // contains filtered or unexported fields }
Database containing key-value pairs of data.
func CreateDatabase ¶
CreateDatabase creates a new database with a name.
func (*Database) DeleteAllKeys ¶ added in v0.5.0
func (db *Database) DeleteAllKeys()
DeleteAllKeys deletes all the keys.
func (*Database) DeleteHashMapFields ¶ added in v0.8.0
func (db *Database) DeleteHashMapFields(key DatabaseKey, fields []string) (uint32, bool)
DeleteHashMapFields removes fields from a HashMap using a key. Returns the number of removed fields. The returned bool is true if the key exists and holds a HashMap.
func (*Database) DeleteKey ¶
func (db *Database) DeleteKey(key DatabaseKey) bool
DeleteKey deletes a key and the value it is holding. Returns true if the key exists and it was deleted. Returns false if the key doesn't exist.
func (*Database) GetAllHashMapFieldsAndValues ¶ added in v0.9.0
func (db *Database) GetAllHashMapFieldsAndValues(key DatabaseKey) (map[string]string, bool)
GetAllHashMapFieldsAndValues returns all the fields and values of a HashMap. The returned map is empty if the key doesn't exist. The returned bool is true if the key exists and holds a HashMap.
func (*Database) GetHashMapFieldValue ¶ added in v0.7.0
func (db *Database) GetHashMapFieldValue(key DatabaseKey, field string) (string, bool)
GetHashMapFieldValue returns a single HashMap field value using a key. The returned bool is true if the field exists in the HashMap, or false if the key or field doesn't exist.
func (*Database) GetKeyCount ¶
GetKeyCount returns the number of keys in the database.
func (*Database) GetStoredSizeBytes ¶
GetStoredSizeBytes returns the size of stored data in bytes.
func (*Database) GetString ¶
func (db *Database) GetString(key DatabaseKey) (DatabaseStringValue, bool)
GetString retrieves a string value using a key. The returned bool is true if the key exists.
func (*Database) GetTypeOfKey ¶ added in v0.8.0
func (db *Database) GetTypeOfKey(key DatabaseKey) (string, bool)
GetTypeOfKey returns the data type of the key if it exists. The returned bool is true if the key exists and false if it doesn't.
func (*Database) SetHashMap ¶ added in v0.7.0
func (db *Database) SetHashMap(key DatabaseKey, fields map[string]string)
SetHashMap sets fields in a HashMap value using a key, overwriting previous fields. Creates the key if it doesn't exist.
func (*Database) SetString ¶
func (db *Database) SetString(key DatabaseKey, value DatabaseStringValue)
SetString sets a string value using a key, overwriting previous value. Creates the key if it doesn't exist.
type DatabaseKey ¶
type DatabaseKey string
DatabaseKey represents key-value pair key. Key is stored as string.
type DatabaseStringValue ¶
type DatabaseStringValue string
DatabaseStringValue represents key-value pair string value. Value is stored as string.
type DefaultLogger ¶
type DefaultLogger struct { Logger *log.Logger FileLogger *log.Logger // contains filtered or unexported fields }
DefaultLogger is a default implementation of the Logger interface. Log output defaults to standard error stream. Debug logs are disabled by default. Call EnableDebug to enable them.
func NewDefaultLogger ¶
func NewDefaultLogger() *DefaultLogger
func (*DefaultLogger) ClearFlags ¶
func (l *DefaultLogger) ClearFlags()
func (*DefaultLogger) CloseLogFile ¶ added in v0.6.0
func (l *DefaultLogger) CloseLogFile() error
func (*DefaultLogger) Debug ¶
func (l *DefaultLogger) Debug(v ...any)
func (*DefaultLogger) Debugf ¶
func (l *DefaultLogger) Debugf(format string, v ...any)
func (*DefaultLogger) Disable ¶
func (l *DefaultLogger) Disable()
func (*DefaultLogger) EnableDebug ¶
func (l *DefaultLogger) EnableDebug()
func (*DefaultLogger) EnableLogFile ¶ added in v0.6.0
func (l *DefaultLogger) EnableLogFile(filePath string) error
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(v ...any)
func (*DefaultLogger) Errorf ¶
func (l *DefaultLogger) Errorf(format string, v ...any)
func (*DefaultLogger) Fatal ¶
func (l *DefaultLogger) Fatal(v ...any)
func (*DefaultLogger) Fatalf ¶
func (l *DefaultLogger) Fatalf(format string, v ...any)
func (*DefaultLogger) Info ¶
func (l *DefaultLogger) Info(v ...any)
func (*DefaultLogger) Infof ¶
func (l *DefaultLogger) Infof(format string, v ...any)
func (*DefaultLogger) Warning ¶
func (l *DefaultLogger) Warning(v ...any)
func (*DefaultLogger) Warningf ¶
func (l *DefaultLogger) Warningf(format string, v ...any)
type Logger ¶
type Logger interface { Debug(v ...any) Debugf(format string, v ...any) Info(v ...any) Infof(format string, v ...any) Error(v ...any) Errorf(format string, v ...any) Warning(v ...any) Warningf(format string, v ...any) Fatal(v ...any) Fatalf(format string, v ...any) // EnableDebug enables debug logs. EnableDebug() // EnableLogFile enables log file. EnableLogFile(filePath string) error // CloseLogFile closes the log file for I/O operations. CloseLogFile() error // ClearFlags clears all default logger output flags. ClearFlags() // Disable disables all log outputs. Disable() }