storage

package
v0.3.41 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidDsn                      = errors.New("invalid_dsn")
	ErrorDriverNotImplemented            = errors.New("driver_not_implemented")
	ErrorDatabaseDoesNotExists           = errors.New("database_does_not_exists")
	ErrorCollectionDoesNotExists         = errors.New("collection_does_not_exists")
	ErrorDatabaseCacheCannotAuthenticate = errors.New("database_cache_cannot_authenticate")
	ErrorDatabaseCacheNotEnabled         = errors.New("database_cache_not_enabled")

	ErrorEntityAlreadyRegistered = errors.New("entity_already_registered")
	ErrorEntityDoesNotExists     = errors.New("entity_does_not_exists")

	ErrorTokenDoesNotExists = errors.New("token_does_not_exists")
	ErrorTokenExpired       = errors.New("token_expired")
)
View Source
var (
	CollectionAuth  = "auth"  // users authentication
	CollectionCache = "cache" // tokens cache
	CollectionOTP   = "otp"
)
View Source
var (
	ArangoConst = struct {
		FieldKey     string
		FieldExpire  string
		FieldOTP     string
		IndexPersist string
		IndexGeo     string
		IndexGeoJson string
	}{
		FieldKey:     "_key",
		FieldExpire:  "_expire",
		FieldOTP:     "otp",
		IndexPersist: "persist",
		IndexGeo:     "geo",
		IndexGeoJson: "geojson",
	}
)
View Source
var (
	BoltConst = struct {
		FieldKey    string
		FieldExpire string
		FieldOTP    string
	}{
		FieldKey:    "_key",
		FieldExpire: "_expire",
		FieldOTP:    "otp",
	}
)

Functions

func BuildKey

func BuildKey(username, password string) string

func DecryptPayload

func DecryptPayload(key []byte, value string) (map[string]interface{}, error)

func DecryptText

func DecryptText(key []byte, value string) (string, error)

func EncryptPayload

func EncryptPayload(key []byte, value map[string]interface{}) (string, error)

func EncryptText

func EncryptText(key []byte, value string) (string, error)

func GenerateOTP

func GenerateOTP(onlyDigits bool, len int) (otp string)

Types

type Auth

type Auth struct {
	Key     string `gorm:"index:auth_key,unique"`
	Payload string
}

Auth "auth" table

type Cache

type Cache struct {
	Key    string `gorm:"index:cache_key,unique"`
	Token  string
	Expire int
}

Cache "cache" table

type DriverArango

type DriverArango struct {
	// contains filtered or unexported fields
}

func NewDriverArango

func NewDriverArango(dsn *Dsn) *DriverArango

func (*DriverArango) AuthGet

func (instance *DriverArango) AuthGet(key string) (payload string, err error)

func (*DriverArango) AuthOverwrite

func (instance *DriverArango) AuthOverwrite(key, payload string) error

func (*DriverArango) AuthRegister

func (instance *DriverArango) AuthRegister(key, payload string) error

func (*DriverArango) AuthRemove

func (instance *DriverArango) AuthRemove(key string) error

func (*DriverArango) CacheAdd

func (instance *DriverArango) CacheAdd(key, token string, duration time.Duration) error

func (*DriverArango) CacheGet

func (instance *DriverArango) CacheGet(key string) (string, error)

func (*DriverArango) CacheRemove

func (instance *DriverArango) CacheRemove(key string) error

func (*DriverArango) Close

func (instance *DriverArango) Close() error

func (*DriverArango) Collection

func (instance *DriverArango) Collection(name string, createIfDoesNotExists bool) (*DriverArangoCollection, error)

func (*DriverArango) Count

func (instance *DriverArango) Count(query string, bindVars map[string]interface{}) (int64, error)

func (*DriverArango) Delete

func (instance *DriverArango) Delete(collectionName string, item interface{}) (map[string]interface{}, error)

func (*DriverArango) EnableCache

func (instance *DriverArango) EnableCache(value bool)

func (*DriverArango) Enabled

func (instance *DriverArango) Enabled() bool

func (*DriverArango) Exec

func (instance *DriverArango) Exec(query string, bindVars map[string]interface{}) (interface{}, error)

func (*DriverArango) Insert

func (instance *DriverArango) Insert(collectionName string, item map[string]interface{}) (map[string]interface{}, error)

func (*DriverArango) OTPNew

func (instance *DriverArango) OTPNew(key string, len int, onlyDigits bool, duration time.Duration) (response string, err error)

func (*DriverArango) OTPVerify

func (instance *DriverArango) OTPVerify(key, otp string) (response bool, err error)

func (*DriverArango) Open

func (instance *DriverArango) Open() error

func (*DriverArango) Query

func (instance *DriverArango) Query(query string, bindVars map[string]interface{}) ([]interface{}, error)

func (*DriverArango) Update

func (instance *DriverArango) Update(collectionName string, item map[string]interface{}) (map[string]interface{}, error)

func (*DriverArango) Upsert

func (instance *DriverArango) Upsert(collectionName string, item map[string]interface{}) (map[string]interface{}, error)

type DriverArangoCollection

type DriverArangoCollection struct {
	// contains filtered or unexported fields
}

func (*DriverArangoCollection) Count

func (instance *DriverArangoCollection) Count() (int64, error)

func (*DriverArangoCollection) EnsureIndex

func (instance *DriverArangoCollection) EnsureIndex(typeName string, fields []string, unique bool) (bool, error)

func (*DriverArangoCollection) Exists

func (instance *DriverArangoCollection) Exists(key string) (bool, error)

func (*DriverArangoCollection) Name

func (instance *DriverArangoCollection) Name() string

func (*DriverArangoCollection) Read

func (instance *DriverArangoCollection) Read(key string) (map[string]interface{}, driver.DocumentMeta, error)

func (*DriverArangoCollection) Remove

func (instance *DriverArangoCollection) Remove(key string) (driver.DocumentMeta, error)

func (*DriverArangoCollection) RemoveIndex

func (instance *DriverArangoCollection) RemoveIndex(typeName string, fields []string) (bool, error)

func (*DriverArangoCollection) Upsert

func (instance *DriverArangoCollection) Upsert(doc map[string]interface{}) (map[string]interface{}, driver.DocumentMeta, error)

type DriverBolt

type DriverBolt struct {
	// contains filtered or unexported fields
}

func NewDriverBolt

func NewDriverBolt(dsn ...interface{}) *DriverBolt

func (*DriverBolt) AuthGet

func (instance *DriverBolt) AuthGet(key string) (payload string, err error)

func (*DriverBolt) AuthOverwrite

func (instance *DriverBolt) AuthOverwrite(key, payload string) error

func (*DriverBolt) AuthRegister

func (instance *DriverBolt) AuthRegister(key, payload string) error

func (*DriverBolt) AuthRemove

func (instance *DriverBolt) AuthRemove(key string) (err error)

func (*DriverBolt) CacheAdd

func (instance *DriverBolt) CacheAdd(key, token string, duration time.Duration) error

func (*DriverBolt) CacheGet

func (instance *DriverBolt) CacheGet(key string) (string, error)

func (*DriverBolt) CacheRemove

func (instance *DriverBolt) CacheRemove(key string) error

func (*DriverBolt) Close

func (instance *DriverBolt) Close() error

func (*DriverBolt) EnableCache

func (instance *DriverBolt) EnableCache(value bool)

func (*DriverBolt) Enabled

func (instance *DriverBolt) Enabled() bool

func (*DriverBolt) OTPNew

func (instance *DriverBolt) OTPNew(key string, len int, onlyDigits bool, duration time.Duration) (response string, err error)

func (*DriverBolt) OTPVerify

func (instance *DriverBolt) OTPVerify(key, otp string) (response bool, err error)

func (*DriverBolt) Open

func (instance *DriverBolt) Open() error

type DriverGorm

type DriverGorm struct {
	// contains filtered or unexported fields
}

func NewDriverGorm

func NewDriverGorm(driverName string, dsn ...interface{}) *DriverGorm

func (*DriverGorm) AuthGet

func (instance *DriverGorm) AuthGet(key string) (payload string, err error)

func (*DriverGorm) AuthOverwrite

func (instance *DriverGorm) AuthOverwrite(key, payload string) error

func (*DriverGorm) AuthRegister

func (instance *DriverGorm) AuthRegister(key, payload string) error

func (*DriverGorm) AuthRemove

func (instance *DriverGorm) AuthRemove(key string) (err error)

func (*DriverGorm) CacheAdd

func (instance *DriverGorm) CacheAdd(key, token string, duration time.Duration) error

func (*DriverGorm) CacheGet

func (instance *DriverGorm) CacheGet(key string) (string, error)

func (*DriverGorm) CacheRemove

func (instance *DriverGorm) CacheRemove(key string) error

func (*DriverGorm) Close

func (instance *DriverGorm) Close() error

func (*DriverGorm) EnableCache

func (instance *DriverGorm) EnableCache(value bool)

func (*DriverGorm) Enabled

func (instance *DriverGorm) Enabled() bool

func (*DriverGorm) GetMode

func (instance *DriverGorm) GetMode() string

func (*DriverGorm) OTPNew

func (instance *DriverGorm) OTPNew(key string, long int, onlyDigits bool, duration time.Duration) (response string, err error)

func (*DriverGorm) OTPVerify

func (instance *DriverGorm) OTPVerify(key, otp string) (response bool, err error)

func (*DriverGorm) Open

func (instance *DriverGorm) Open() error

func (*DriverGorm) SetMode

func (instance *DriverGorm) SetMode(value string) *DriverGorm

type Dsn

type Dsn struct {
	User     string
	Password string
	Protocol string
	Host     string
	Port     int
	Database string
}

"admin:xxxxxxxxx@tcp(localhost:3306)/test"

func NewDsn

func NewDsn(dsn ...string) *Dsn

func (*Dsn) GoString

func (instance *Dsn) GoString() string

func (*Dsn) IsValid

func (instance *Dsn) IsValid() bool

func (*Dsn) String

func (instance *Dsn) String() string

String return dsn string. i.e. "admin:xxxxxxxx@tcp(localhost:3306)/test"

type IDatabase

type IDatabase interface {
	Enabled() bool
	Open() error
	Close() error
	EnableCache(value bool)
	AuthRegister(key, payload string) error
	AuthGet(key string) (string, error)
	AuthRemove(key string) error
	AuthOverwrite(key, payload string) error

	CacheGet(key string) (string, error)
	CacheRemove(key string) error
	CacheAdd(key, token string, duration time.Duration) error // add new or update existing

	OTPNew(key string, len int, onlyDigits bool, duration time.Duration) (string, error)
	OTPVerify(key, otp string) (bool, error)
}

func NewDatabase

func NewDatabase(driverName, connectionString string, isCache bool) (driver IDatabase, err error)

type Otp

type Otp struct {
	Key    string `gorm:"index:otp_key,unique"`
	Otp    string `gorm:"index:otp_otp"`
	Expire int
}

Jump to

Keyboard shortcuts

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