storage

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository interface {
	AssertCredentials(ctx context.Context, username, password []byte) error
	AddUser(ctx context.Context, user []byte) error
	GetUserByUsername(ctx context.Context, username string) (*models.User, error)
	AddFollowRecord(ctx context.Context, follower string, target string) error
	DeleteFollowRecord(ctx context.Context, follower string, target string) error
	GetFollowers(ctx context.Context, username string) (models.UserSlice, error)
	GetFollowing(ctx context.Context, username string) (models.UserSlice, error)
	AddPost(ctx context.Context, username string, post []byte) error
	GetTargetsPosts(ctx context.Context, username string) (models.PostSlice, error)
}

Repository wraps the storage and provides domain specific functions to interact with the storage

func NewRepository

func NewRepository(storage Storage) Repository

NewRepository returns new repository for a given storage

type RepositoryImpl added in v0.0.2

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

RepositoryImpl implements Repository in order to interact with storage

func (*RepositoryImpl) AddFollowRecord added in v0.0.2

func (r *RepositoryImpl) AddFollowRecord(ctx context.Context, follower string, target string) error

AddFollowRecord adds a follow relation between two users of type `follower follows target`

func (*RepositoryImpl) AddPost added in v0.0.2

func (r *RepositoryImpl) AddPost(ctx context.Context, username string, post []byte) error

AddPost adds a post to a given users profile

func (*RepositoryImpl) AddUser added in v0.0.2

func (r *RepositoryImpl) AddUser(ctx context.Context, user []byte) error

AddUser adds user given as byte slice into the database

func (*RepositoryImpl) AssertCredentials added in v0.0.2

func (r *RepositoryImpl) AssertCredentials(ctx context.Context, username, password []byte) error

AssertCredentials checks if given username and password are the same as persisted into the database

func (*RepositoryImpl) DeleteFollowRecord added in v0.0.2

func (r *RepositoryImpl) DeleteFollowRecord(ctx context.Context, follower string, target string) error

DeleteFollowRecord deletes a follow relation between two users

func (*RepositoryImpl) GetFollowers added in v0.0.2

func (r *RepositoryImpl) GetFollowers(ctx context.Context, username string) (models.UserSlice, error)

GetFollowers returns all the followers of a given user

func (*RepositoryImpl) GetFollowing added in v0.0.2

func (r *RepositoryImpl) GetFollowing(ctx context.Context, username string) (models.UserSlice, error)

GetFollowing returns all the users who follow a given user

func (*RepositoryImpl) GetTargetsPosts added in v0.0.2

func (r *RepositoryImpl) GetTargetsPosts(ctx context.Context, username string) (models.PostSlice, error)

GetTargetsPosts returns all the posts which a given user can see

func (*RepositoryImpl) GetUserByUsername added in v0.0.2

func (r *RepositoryImpl) GetUserByUsername(ctx context.Context, username string) (*models.User, error)

GetUserByUsername returns user entity for a given user identified by username

type Settings

type Settings struct {
	Type              string `mapstructure:"type" description:"Type of the storage"`
	URI               string `mapstructure:"uri" description:"URI of the storage"`
	SkipSSLValidation bool   `mapstructure:"skip_ssl_validation" description:"whether to skip ssl verification when connecting to the storage"`
}

Settings holds all storage configuration settings

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings returns default settings for the storage

func (*Settings) Validate

func (s *Settings) Validate() error

Validate validates the storage settings

type Storage

type Storage interface {
	Get() *sql.DB
	Transaction(context context.Context, operation func(context context.Context, tx *sql.Tx) error) error
	Close() error
}

Storage interface represents a Transactional Database

func New

func New(s *Settings) (Storage, error)

New creates a Storage object and updates the database with the latest migrations

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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