helpers

package
v0.0.0-...-4a8b94e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Shared table defaults
	DefaultPartitionMax uint16 = 250
	PartitionMin        uint16 = 1
	DefaultMaxEntries   uint64 = 0
	DefaultEncryptCost  int    = 4
	EncryptCostMax      int    = 31
	EncryptCostMin      int    = 4
)
View Source
const (
	FileTypeConfig  = ".gdbconf"
	FileTypeLog     = ".gdbl"
	FileTypeStorage = ".gdbs"
)

File types

View Source
const (
	// Unexpected error
	ErrorUnexpected = 1000 + iota // Unexpected internal error...

	// Generic Table Query Errors
	ErrorTableExists
	ErrorTableDoesntExist
	ErrorTableNameRequired
	ErrorInvalidKeyCharacters
	ErrorTableFull
	ErrorQueryInvalidFormat
	ErrorNoEntryFound
)
View Source
const (
	// Schema creation errors
	ErrorSchemaRequired = 2001 + iota
	ErrorSchemaItemsRequired
	ErrorSchemaInvalidItemName
	ErrorSchemaInvalidItemPosition
	ErrorSchemaInvalidItemType
	ErrorSchemaInvalidItemParameters
	ErrorSchemaInvalidFormat
	ErrorSchemaInvalidTimeFormat
	ErrorSchemaInvalid
	ErrorObjectItemNotRequired // 2010

	// Query Schema errors
	ErrorInvalidItem
	ErrorInvalidItemValue
	ErrorInvalidMethod
	ErrorInvalidMethodParameters
	ErrorTooManyMethodParameters
	ErrorNotEnoughMethodParameters
	ErrorMissingRequiredItem
	ErrorStringTooLarge
	ErrorStringRequired
	ErrorStringIsEncrypted // 2020
	ErrorEncryptingString
	ErrorArrayItemsRequired
	ErrorArrayEmpty
	ErrorArrayItemNotSortable
	ErrorIndexOutOfBounds
	ErrorMapItemsRequired
	ErrorInvalidTimeFormat
	ErrorUniqueValueDuplicate
	ErrorRestoreItemSchema
)
View Source
const (
	// Keystore Errors
	ErrorKeyRequired = 3001 + iota
	ErrorKeyInUse
)
View Source
const (
	// Auth Table Query Errors
	ErrorNameRequired = 4001 + iota
	ErrorNameInUse
	ErrorInvalidNameCharacters
	ErrorPasswordLength
	ErrorPasswordEncryption
	ErrorNoEmailItem
	ErrorIncorrectAuthType
	ErrorInvalidEmail
)
View Source
const (
	// Leaderboard errors
	ErrorLeaderboardExists = 5001 + iota
	ErrorLeaderboardDoesntExist
)
View Source
const (
	// Storage errors
	ErrorStorageNotInitialized = 9001 + iota
	ErrorTableFolderCreate
	ErrorCreatingFolder
	ErrorFileOpen
	ErrorFileAppend
	ErrorFileUpdate
	ErrorFileRead
	ErrorFileWrite
	ErrorFileDelete // 6010
	ErrorJsonEncoding
	ErrorJsonDecoding
	ErrorJsonDataFormat
	ErrorJsonIndexingFormat
	ErrorInternalFormatting
)

Variables

View Source
var (
	// Faster JSON Mashaling
	Fjson = jsoniter.ConfigCompatibleWithStandardLibrary
)

Functions

func Abs

func Abs(i int) int

func CloseLogger

func CloseLogger()

CloseLogger closes the logger. Any subsequent logs will only be output to the console.

func EncryptString

func EncryptString(str string, cost int) ([]byte, error)

EncryptString encrypts a `string` with the `golang.org/x/crypto/bcrypt` library at a given cost.

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes uses the `crypto/rand` library to create a secure random `[]byte` at a given size `n`.

func GenerateSecureString

func GenerateSecureString(n int) (string, error)

GenerateSecureString uses the `crypto/rand` and `encoding/base64` libraries to create a random `string` of given length `n`.

func HashString

func HashString(s string) int

HashString hashes a string into a number viable for use as a key

func InitLogger

func InitLogger(prio int, maxSize int) error

InitLogger initializes the logging system and returns an error if anything goes wrong. The logger can only be used if it is successfully initialized.

func Log

func Log(in string, priority int) bool

Log appends the given string to the current log file. If the priority level is less than the minimum priority level threshold, the log will not be written.

func LogAndPrint

func LogAndPrint(in string, priority int) bool

func StringMatchesEncryption

func StringMatchesEncryption(str string, hash []byte) bool

StringMatchesEncryption uses the `golang.org/x/crypto/bcrypt` library to compare a `string` to an encrypted `[]byte`. Returns true if the `string` matches the encrypted `[]byte`.

Types

type Error

type Error struct {
	ID   int    // Error ID number
	From string // From whence it came, and general error messages
}

func NewError

func NewError(id int, from string) Error

NewError creates a new Error message with given ID and From message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL