mongodb

package
v0.0.0-...-c7c103a Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

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

func NewMongoClient

func NewMongoClient(uri string) (*mongo.Client, error)

NewMongoClient takes a single parameter uri and returns either an nil, and error, or a newly created MongoDB Client object

Types

type Repository

type Repository struct {
	DB         string
	Collection string
	Client     *mongo.Client
}

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) GetInfo

func (r Repository) GetInfo() ([]models.Shortener, error)

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.

func (Repository) URLExists

func (r Repository) URLExists(u string) (bool, error)

URLExists is a function that checks the existance of a url in the database

Jump to

Keyboard shortcuts

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