1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2024-11-27 18:45:40 +00:00
imgsrv/get.go
Vincent Batts 2c78e94b2c config: reimplementing the configuration to be in YAML
cleanup: beginning to separate out into multiple files
2013-02-08 23:29:43 -05:00

31 lines
687 B
Go

package main
import (
"labix.org/v2/mgo/bson"
)
/* gfs is a *mgo.GridFS defined in imgsrv.go */
func GetFileByFilename(filename string) (this_file File, err error) {
err = gfs.Find(bson.M{"filename":filename}).One(&this_file)
if (err != nil) {
return this_file, err
}
return this_file, nil
}
func GetFileRandom() (this_file File, err error) {
r := rand64()
err = gfs.Find(bson.M{"random": bson.M{"$gt" : r } }).One(&this_file)
if (err != nil) {
return this_file, err
}
if (len(this_file.Md5) == 0) {
err = gfs.Find(bson.M{"random": bson.M{"$lt" : r } }).One(&this_file)
}
if (err != nil) {
return this_file, err
}
return this_file, nil
}