mongo

package
v0.0.0-...-2718fd8 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2014 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DB is the current mongo database connection
	DB *mgo.Database

	// Collection is the only collection that we use with mongo (hippos ATM)
	Collection *mgo.Collection

	// GridFS is were we store our images in Mongo
	GridFS *mgo.GridFS
)

Functions

func Init

func Init() (*mgo.Session, error)

Types

type Hippo

type Hippo struct {
	ID bson.ObjectId `bson:"_id"json:"id"`

	Filename string `json:"-"`

	URL      string `json:"url"`
	Verified bool   `json:"verified"`
	Votes    int    `json:"votes"`

	// Weird way of getting a random doc, but:
	// http://cookbook.mongodb.org/patterns/random-attribute/
	Random float32 `json:"-"`
}

Hippo is the struct used to store the information that we save in mongo and we return to the user in JSON format

func GetHippoByMD5

func GetHippoByMD5(md5checksum string) (*Hippo, error)

checks if there's an entry with the received MD5 if there's it returns the Hippo

func InsertHippo

func InsertHippo(fileBytes []byte) (*Hippo, error)

InsertHippo will store the Hippo on GridFS and return the Hippo document created

func (Hippo) JSON

func (h Hippo) JSON() []byte

JSON is going to return the marshalled version of the struct

func (*Hippo) Populate

func (h *Hippo) Populate()

Populate is going to set the "calculated" fields to the struct

Jump to

Keyboard shortcuts

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