data

package
v0.0.0-...-9192568 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateStorageTable = `` /* 260-byte string literal not displayed */

	DeleteData       = "DELETE FROM storage WHERE uid = $1 AND id = $2"
	GetAllDataByType = "SELECT * FROM storage WHERE uid = $1 AND type = $2"
	GetDataByID      = "SELECT * FROM storage WHERE uid = $1 AND id = $2"
	StoreData        = `
		INSERT INTO storage(uid, data, type) VALUES($1, $2, $3) ON CONFLICT DO NOTHING RETURNING id
	`
)

Variables

View Source
var (
	ErrDBMissingURL = errors.New("data db url is missing")
	ErrNotFound     = errors.New("data not found")
	ErrEmpty        = errors.New("data is missing or empty")
	ErrMissingArgs  = errors.New("user id or data type is not specified")
)

Functions

This section is empty.

Types

type BasicRepo

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

func NewBasicRepo

func NewBasicRepo() *BasicRepo

func (*BasicRepo) DeleteData

func (r *BasicRepo) DeleteData(_ context.Context, uid, id string) error

func (*BasicRepo) GetAllDataByType

func (r *BasicRepo) GetAllDataByType(_ context.Context, uid string,
	t StorageType,
) ([]SecureData, error)

func (*BasicRepo) GetDataByID

func (r *BasicRepo) GetDataByID(_ context.Context, uid, id string) (SecureData, error)

func (*BasicRepo) StoreData

func (r *BasicRepo) StoreData(_ context.Context, data SecureData) (string, error)

type DBRepo

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

func NewDBRepo

func NewDBRepo(url string) (*DBRepo, error)

func (*DBRepo) DeleteData

func (r *DBRepo) DeleteData(ctx context.Context, uid, id string) error

func (*DBRepo) GetAllDataByType

func (r *DBRepo) GetAllDataByType(ctx context.Context, uid string,
	t StorageType,
) ([]SecureData, error)

func (*DBRepo) GetDataByID

func (r *DBRepo) GetDataByID(ctx context.Context, uid, id string) (SecureData, error)

func (*DBRepo) StoreData

func (r *DBRepo) StoreData(ctx context.Context, data SecureData) (string, error)

type IRepository

type IRepository interface {
	DeleteData(ctx context.Context, uid, id string) error
	GetAllDataByType(ctx context.Context, uid string, t StorageType) ([]SecureData, error)
	GetDataByID(ctx context.Context, uid, id string) (SecureData, error)
	StoreData(ctx context.Context, data SecureData) (string, error)
}

func NewRepo

func NewRepo(repoURL string) (IRepository, error)

type SecureData

type SecureData struct {
	UID  string      `json:"-"`
	ID   string      `json:"id"`
	Data []byte      `json:"data"`
	Type StorageType `json:"-"`
}

type Service

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

func NewService

func NewService(repoURL string) (Service, error)

NewService returns an instance of the Service with the associated repository. The repository gets created in accordance with the passed URL.

func (Service) DeleteSecureData

func (s Service) DeleteSecureData(ctx context.Context, uid, id string) error

DeleteSecureData removes the stored data with the unique ID. The method removes the data of the specified user only.

func (Service) GetAllDataByType

func (s Service) GetAllDataByType(ctx context.Context, uid string, t StorageType) ([]SecureData, error)

GetAllDataByType returns all the user's stored data.

func (Service) GetDataByID

func (s Service) GetDataByID(ctx context.Context, uid, id string) (SecureData, error)

GetDataByID returns the stored data by the unique ID. The method returns the data of the specified user only.

func (Service) GetDataFromBytes

func (s Service) GetDataFromBytes(b []byte) ([]byte, error)

GetDataFromBytes transforms the encrypted slice of bytes into the original one.

func (Service) StoreSecureDataFromPayload

func (s Service) StoreSecureDataFromPayload(ctx context.Context, uid string,
	payload any, t StorageType,
) (string, error)

StoreSecureDataFromPayload processes payload of any type into a slice of bytes, encodes the slice, and stores the content in the DB.

type Storage

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

type StorageType

type StorageType int
const (
	SBinary StorageType = iota
	SCard
	SPassword
	SText
)

Jump to

Keyboard shortcuts

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