models

package
v0.0.0-...-ce44bb8 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(c *utils.Config) (*mgo.Session, error)

Connect establishes a new MongoDB session.

func CreateIndexes

func CreateIndexes()

CreateIndexes creates indexes for three collections: url, statistics and counter.

func InsertURL

func InsertURL(doc interface{}) (err error)

InsertURL inserts a document.

func UpdateStats

func UpdateStats(id string) (err error)

UpdateStats updates statistics.

Types

type Counter

type Counter struct {
	ID       string `bson:"_id"`
	Sequence int    `bson:"sequence"`
}

Counter is a document structure for the collection counter. It is used for id sequence.

func FindAndModify

func FindAndModify(updateQuery bson.M) (doc Counter, err error)

FindAndModify offers an atomic incrementation operation.

type Server

type Server struct {
	Version    string `json:"version"`
	Platform   string `json:"platform"`
	GoVersion  string `json:"go"`
	GoPlatform string `json:"goPlatform"`
}

Server information about version, go version and platform.

type Stats

type Stats struct {
	Clicks int `bson:"clicks" json:"clicks,omitempty"`
}

Stats is a document structure for the collection statistics. It is used for making statistics.

type URL

type URL struct {
	Status    int        `bson:",omitempty" json:"status"`
	Hash      string     `bson:"hash" json:"-"`
	ID        string     `bson:"id" json:"id,omitempty"`
	TargetURL string     `bson:",omitempty" json:"targeturl,omitempty"`
	LongURL   string     `bson:"longurl" json:"longurl,omitempty"`
	Timestamp *time.Time `bson:"ts" json:"ts,omitempty"`
	Stats     []Stats    `bson:"stats,omitempty" json:"stats,omitempty"`
}

URL is a document structure for the collection url. It is used to store url(s).

func FindURL

func FindURL(doc bson.M) (resp URL, err error)

FindURL returns document is a structure.

func InfoURL

func InfoURL(id string) (resp []URL, err error)

InfoURL returns document in an array of structures.

func (*URL) ReadyToInsert

func (u *URL) ReadyToInsert(hash string, seq *Counter)

ReadyToInsert fills document.

Jump to

Keyboard shortcuts

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