Documentation ¶
Index ¶
- type Config
- type MongoDB
- func (m *MongoDB) Close() error
- func (m *MongoDB) CreateNewShortURL(userID, longURL, customShortURL string, isGuest bool) (*db.ShortURLInfo, error)
- func (m *MongoDB) CreateUser(username, email string, password []byte) error
- func (m *MongoDB) LoginUser(email string, password []byte) (*db.UserInfo, error)
- func (m *MongoDB) RetrieveShortURLClicks(shortURL string) ([]*db.ShortURLClick, error)
- func (m *MongoDB) RetrieveURLInfo(shortURL string) (*db.ShortURLInfo, error)
- func (m *MongoDB) RetrieveUserInfo(email string) (*db.UserInfo, error)
- func (m *MongoDB) RetrieveUserURLs(email string) ([]*db.ShortURLInfo, error)
- func (m *MongoDB) ToggleShortLinkStatus(shortURL string, disable bool) error
- func (m *MongoDB) UpdateShortURL(shortURL, newLongURL string, click *db.ShortURLClick) error
- func (m *MongoDB) UsernameExists(username string) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // DBName is the name of the database. DBName string `long:"dbname" env:"MONGODB_DB_NAME" default:"bob" description:"MongoDB database name"` // ConnectionUrl is the URL used to connect to the database. ConnectionURL string `long:"connectionurl" env:"MONGODB_CONNECTION_URL" description:"MongoDB connection URL"` }
type MongoDB ¶
type MongoDB struct {
// contains filtered or unexported fields
}
MongoDB is the database handler for MongoDB. Implements db.DataStore.
func (*MongoDB) CreateNewShortURL ¶
func (m *MongoDB) CreateNewShortURL(userID, longURL, customShortURL string, isGuest bool) (*db.ShortURLInfo, error)
CreateNewShortURL creates a new short URL. "userID" is the user's email if they are logged in, otherwise it is the unique identifier for the guest user.
func (*MongoDB) CreateUser ¶
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. Implements db.DataStore.
func (*MongoDB) LoginUser ¶
LoginUser logs a user in and returns a nil error if the user exists and the password is correct. Implements db.DataStore.
func (*MongoDB) RetrieveShortURLClicks ¶
func (m *MongoDB) RetrieveShortURLClicks(shortURL string) ([]*db.ShortURLClick, error)
RetrieveShortURLClicks returns a list of complete click information for a short URL.
func (*MongoDB) RetrieveURLInfo ¶
func (m *MongoDB) RetrieveURLInfo(shortURL string) (*db.ShortURLInfo, error)
RetrieveURLInfo fetches information about a short URL using the shortened URL. Implements db.DataStore.
func (*MongoDB) RetrieveUserInfo ¶
RetrieveUserInfo fetches information about a user using the email. Implements db.DataStore.
func (*MongoDB) RetrieveUserURLs ¶
func (m *MongoDB) RetrieveUserURLs(email string) ([]*db.ShortURLInfo, error)
RetrieveUserURLs fetches all the shorted URLs for the specified user. Implements db.DataStore.
func (*MongoDB) ToggleShortLinkStatus ¶
ToggleShortLinkStatus enables/disables a short link.
func (*MongoDB) UpdateShortURL ¶
func (m *MongoDB) UpdateShortURL(shortURL, 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.