storage

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](v T) *T

Types

type Account

type Account struct {
	ID             string         `json:"id" bson:"_id"`
	Namespace      string         `json:"namespace"`
	Authentication AccountAuth    `json:"-" bson:"authentication"`
	Data           map[string]any `json:"data"`
	Metadata       map[string]any `json:"metadata"`
}

type AccountAuth

type AccountAuth struct {
	Local *LocalAuth `bson:"local,omitempty"`
}

type DBStorage

type DBStorage interface {
	GetAccount(id string) (*Account, error)
	LocalAuthentication(namespace string, username *string, email *string, phone_number *string) (*Account, error)
	GetAccounts(namespaces []string) ([]Account, error)
	GetAccountsByIds(accountids []string) ([]Account, error)
	CreateAccount(account Account) error

	//TODO : remove UpdateAccount, implement UpdateAccountData and UpdateAccountLocalAuthentication
	UpdateAccount(account Account) error

	Migrate() error
}

func NewDBStorage

func NewDBStorage(cfg *viper.Viper) (DBStorage, error)

type EtcdKVStore

type EtcdKVStore struct {
	Client *clientv3.Client
}

func NewEtcdKVStore

func NewEtcdKVStore(cfg *viper.Viper) (EtcdKVStore, error)

func (EtcdKVStore) Delete

func (s EtcdKVStore) Delete(k string) error

func (EtcdKVStore) Get

func (s EtcdKVStore) Get(k string) (any, error)

func (EtcdKVStore) Put

func (s EtcdKVStore) Put(k string, v any) error

func (EtcdKVStore) PutWithTTL

func (s EtcdKVStore) PutWithTTL(k string, v any, duration time.Duration) error

type KVStore

type KVStore interface {
	Put(string, any) error
	PutWithTTL(string, any, time.Duration) error
	Get(string) (any, error)
	Delete(string) error
}

func NewKVStore

func NewKVStore(cfg *viper.Viper) (KVStore, error)

type LocalAuth

type LocalAuth struct {
	Username              *string     `json:"username" bson:"username,omitempty"`
	Password              string      `json:"password" bson:"password"`
	Email                 *string     `json:"email" bson:"email,omitempty"`
	EmailValidation       *Validation `json:"email_validation"  bson:"email_validation,omitempty"`
	PhoneNumber           *string     `json:"phone_number"  bson:"phone_number,omitempty"`
	PhoneNumberValidation *Validation `json:"phone_number_validation"  bson:"phone_number_validation,omitempty"`
}

type MongoDBStorage

type MongoDBStorage struct {
	*mongo.Client
	DbName      string
	Collections map[string]string
}

func NewMongoDBStorage

func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error)

func (MongoDBStorage) CreateAccount

func (s MongoDBStorage) CreateAccount(account Account) error

func (MongoDBStorage) GetAccount

func (s MongoDBStorage) GetAccount(id string) (*Account, error)

func (MongoDBStorage) GetAccounts

func (s MongoDBStorage) GetAccounts(namespaces []string) (accounts []Account, err error)

func (MongoDBStorage) GetAccountsByIds

func (s MongoDBStorage) GetAccountsByIds(accountids []string) (accounts []Account, err error)

func (MongoDBStorage) LocalAuthentication

func (s MongoDBStorage) LocalAuthentication(namespace string, username *string, email *string, phone_number *string) (*Account, error)

LocalAuthentication returns an Account matching with one of username, email or password. If username, is provided (not an empty string), it will search by username only If username is an empty string and email is provided, it will search by email If both username and email are empty strings, phone_number must be provided and it will search by phone number

func (MongoDBStorage) Migrate

func (s MongoDBStorage) Migrate() error

func (MongoDBStorage) UpdateAccount

func (s MongoDBStorage) UpdateAccount(account Account) error

type PostgresqlStorage

type PostgresqlStorage struct {
	DbConnection *sql.DB
	Schema       string
	Tables       map[string]string
}

func NewPostgresqlStorage

func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error)

func (PostgresqlStorage) CreateAccount

func (psql PostgresqlStorage) CreateAccount(account Account) error

func (PostgresqlStorage) GetAccount

func (psql PostgresqlStorage) GetAccount(id string) (*Account, error)

func (PostgresqlStorage) GetAccounts

func (psql PostgresqlStorage) GetAccounts(namespaces []string) ([]Account, error)

func (PostgresqlStorage) GetAccountsByIds

func (psql PostgresqlStorage) GetAccountsByIds(accountids []string) ([]Account, error)

func (PostgresqlStorage) LocalAuthentication

func (psql PostgresqlStorage) LocalAuthentication(namespace string, username *string, email *string, phone_number *string) (*Account, error)

func (PostgresqlStorage) Migrate

func (psql PostgresqlStorage) Migrate() error

func (PostgresqlStorage) UpdateAccount

func (psql PostgresqlStorage) UpdateAccount(account Account) error

type Storage

type Storage struct {
	DB DBStorage
	KV KVStore
}

Storage interface

func NewStorage

func NewStorage(cfg *viper.Viper) (Storage, error)

type Validation

type Validation struct {
	Validated      bool   `json:"validated"  bson:"validated"`
	ValidationCode string `json:"validation_code"  bson:"validation_code"`
}

Jump to

Keyboard shortcuts

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