store

package
v0.0.0-...-b856168 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCannotOpenMediumFile       = err.Const("cannot open medium file")
	ErrCannotReadMediumFile       = err.Const("cannot read medium file")
	ErrCannotUnmarshallMediumFile = err.Const("cannot unmarshall medium file")
	ErrCannotFindMedium           = err.Const("cannot find medium")
)
View Source
const (
	ErrCannotOpenUserFile        = err.Const("cannot open user file")
	ErrCannotReadUserFile        = err.Const("cannot read user file")
	ErrCannotUnmarshallUserFile  = err.Const("cannot unmarshall user file")
	ErrUserAlreadyExists         = err.Const("user already exists")
	ErrUserNotFound              = err.Const("user not found")
	ErrMediumSourceAlreadyExists = err.Const("medium source already exits")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Medium

type Medium struct {
	URL          string    `json:"url"`
	ID           string    `json:"id"`
	Hash         string    `json:"hash"`
	Multiplier   float32   `json:"multiplier"`
	CreatedDate  time.Time `json:"created_date"`
	ModifiedDate time.Time `json:"modified_date"`
	Hit          int       `json:"hit"`
	UserID       string    `json:"user_id"`
}

type MediumFile

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

MediumFile is the type that will store the medium information in a file on disk

func NewMediumFile

func NewMediumFile(ctx context.Context, filename string, ticker time.Duration, elemsInPage int) (*MediumFile, error)

NewMediumFile will create a new instance of MediumFile This is not thread safe

func (*MediumFile) AddSource

func (m *MediumFile) AddSource(ctx context.Context, userID string, source string) error

AddSource will add a new url medium source for a userID

func (*MediumFile) DeleteSource

func (m *MediumFile) DeleteSource(ctx context.Context, userID string, sourceID string) error

DeleteSource will delete a source given the userID and sourceID

func (*MediumFile) GetAllSourceData

func (m *MediumFile) GetAllSourceData(ctx context.Context, userID string, page int) ([]Medium, error)

GetAllSourceData returns the sources on the selected page

func (*MediumFile) GetSources

func (m *MediumFile) GetSources(ctx context.Context, userID string, page int) ([]Source, error)

GetSources returns the sources on the selected page

func (*MediumFile) Start

func (m *MediumFile) Start(ctx context.Context) error

Start will start the background job that will periodically save what's in memory

func (*MediumFile) UpdateSource

func (m *MediumFile) UpdateSource(ctx context.Context, userID string, source Medium) error

UpdateSource will update the given source for the user

type Source

type Source struct {
	URL string
	ID  string
}

Source is the response type

type UserFile

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

UserFile is the type that will store the user information in a file on disk

func NewUserFile

func NewUserFile(ctx context.Context, filename string, ticker time.Duration) (*UserFile, error)

NewUserFile will create a new instance of UserFile This is not thread safe

func (*UserFile) CreateNewUser

func (u *UserFile) CreateNewUser(ctx context.Context, email string) (string, error)

CreateNewUser will create a new user that is needed to add medium sources. It returns the uuid of the new user.

func (*UserFile) GetUser

func (u *UserFile) GetUser(ctx context.Context, email string) (string, error)

GetUser will retrieve the user details. It will return the uuid of the user.

func (*UserFile) IsUser

func (u *UserFile) IsUser(ctx context.Context, userID string) (bool, error)

IsUser checks whether the given userID is valid

func (*UserFile) Start

func (u *UserFile) Start(ctx context.Context) error

Start will start the background job that will periodically save what's in memory

Jump to

Keyboard shortcuts

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