Documentation ¶
Overview ¶
Package mongodb is an example MongoDB client implementation written in Go This package extends a Repository metaphor which wraps access methods for the MongoDB database and collections that are used in the example.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Repository ¶
Repository is a struct used to store details of your MongoDB Database, Collection and a pointer to a MongoDB Client object
func NewMongoRepository ¶
func NewMongoRepository(db, collection string, client *mongo.Client) *Repository
NewMongoRepository takes a Database, a Collection name, a pointer to a MongoDB Client object and returns a pointer to a Repository
func (Repository) GetURL ¶
func (r Repository) GetURL(code string) (string, error)
GetURL is a function that has one receiver of type Repository, accepts a single parameter of type string that is an encoded URL and returns details from the encoded URL. A call to this function results in an update of the document stored in the database such that the visit count is incremented by one.
func (Repository) SaveURL ¶
func (r Repository) SaveURL(url string) (string, error)
SaveURL is a function that has one receiver of type Repository, takes a single url string parameter and generates a shortened url, returning that after it is saved in the database. A call to SaveUrl will result in a document to be created which contains the details of a new generated url.