mem

package
v0.0.0-...-d9c1e7a Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemDB

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

MemDB is an in-memory database.

func New

func New() *MemDB

New returns a new *MemDB instance.

func (*MemDB) Close

func (m *MemDB) Close() error

Close ends the connection to the database.

func (*MemDB) CreateNewShortURL

func (m *MemDB) CreateNewShortURL(userID, longURL, customShortURL string, isGuest bool) (*db.ShortURLInfo, error)

CreateNewShortURL adds a new URL to the database and returns the shortened URL. userID will can be any unique identifier for a guest user but it is an email for non-guest users.

func (*MemDB) CreateUser

func (m *MemDB) CreateUser(username, email string, password []byte) error

CreateUser adds a new user to the database. The username must be unique and email must be unique. The password is hashed before being stored.

func (*MemDB) LoginUser

func (m *MemDB) LoginUser(email string, password []byte) (*db.UserInfo, error)

LoginUser logs a user in and returns a nil error if the user exists and the password is correct.

func (*MemDB) RetrieveShortURLClicks

func (m *MemDB) RetrieveShortURLClicks(shortURL string) ([]*db.ShortURLClick, error)

RetrieveShortURLClicks returns a list of complete click information for a short URL.

func (*MemDB) RetrieveURLInfo

func (m *MemDB) RetrieveURLInfo(short string) (*db.ShortURLInfo, error)

RetrieveURLInfo fetches information about a short URL using the shortened URL.

func (*MemDB) RetrieveUserInfo

func (m *MemDB) RetrieveUserInfo(email string) (*db.UserInfo, error)

RetrieveUserInfo fetches information about a user using the email.

func (*MemDB) RetrieveUserURLs

func (m *MemDB) RetrieveUserURLs(email string) ([]*db.ShortURLInfo, error)

RetrieveUserURLs fetches all the shorted URLs for the specified user.

func (*MemDB) SetError

func (m *MemDB) SetError(err error)

SetError is used by tests to simulate errors.

func (*MemDB) ToggleShortLinkStatus

func (m *MemDB) ToggleShortLinkStatus(shortURL string, disable bool) error

ToggleShortLinkStatus enables/disables a short link.

func (*MemDB) UpdateShortURL

func (m *MemDB) UpdateShortURL(shortURL string, newLongURL string, click *db.ShortURLClick) error

UpdateShortURL updates the information for the specified short URL. This method is used for click update and link editing.

func (*MemDB) UsernameExists

func (m *MemDB) UsernameExists(username string) (bool, error)

UsernameExists checks if a username exists in the database.

Jump to

Keyboard shortcuts

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