mirror of
https://github.com/vbatts/imgsrv.git
synced 2024-11-27 18:45:40 +00:00
my rand helper wasn't helping
This commit is contained in:
parent
15fa357f7a
commit
84e5af9fc2
3 changed files with 6 additions and 9 deletions
|
@ -3,6 +3,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"labix.org/v2/mgo/bson"
|
"labix.org/v2/mgo/bson"
|
||||||
|
"math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* gfs is a *mgo.GridFS defined in imgsrv.go */
|
/* gfs is a *mgo.GridFS defined in imgsrv.go */
|
||||||
|
@ -16,7 +17,7 @@ func GetFileByFilename(filename string) (this_file File, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFileRandom() (this_file File, err error) {
|
func GetFileRandom() (this_file File, err error) {
|
||||||
r := Rand64()
|
r := rand.Int63()
|
||||||
err = gfs.Find(bson.M{"random": bson.M{"$gt" : r } }).One(&this_file)
|
err = gfs.Find(bson.M{"random": bson.M{"$gt" : r } }).One(&this_file)
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
return this_file, err
|
return this_file, err
|
||||||
|
|
5
hash.go
5
hash.go
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/adler32"
|
"hash/adler32"
|
||||||
|
@ -9,10 +8,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Rand64() int64 {
|
|
||||||
return rand.Int63()
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convinience method for getting md5 sum of a string */
|
/* Convinience method for getting md5 sum of a string */
|
||||||
func GetMd5FromString(blob string) (sum []byte) {
|
func GetMd5FromString(blob string) (sum []byte) {
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"labix.org/v2/mgo"
|
"labix.org/v2/mgo"
|
||||||
"labix.org/v2/mgo/bson"
|
"labix.org/v2/mgo/bson"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -142,7 +143,7 @@ func routeFilesPOST(w http.ResponseWriter, r *http.Request) {
|
||||||
var filename string
|
var filename string
|
||||||
info := Info{
|
info := Info{
|
||||||
Ip: r.RemoteAddr,
|
Ip: r.RemoteAddr,
|
||||||
Random: Rand64(),
|
Random: rand.Int63(),
|
||||||
TimeStamp: time.Now(),
|
TimeStamp: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,7 +434,7 @@ func routeGetFromUrl(w http.ResponseWriter, r *http.Request) {
|
||||||
if (r.Method == "POST") {
|
if (r.Method == "POST") {
|
||||||
info := Info{
|
info := Info{
|
||||||
Ip: r.RemoteAddr,
|
Ip: r.RemoteAddr,
|
||||||
Random: Rand64(),
|
Random: rand.Int63(),
|
||||||
TimeStamp: time.Now(),
|
TimeStamp: time.Now(),
|
||||||
}
|
}
|
||||||
log.Println(info)
|
log.Println(info)
|
||||||
|
@ -512,7 +513,7 @@ func routeUpload(w http.ResponseWriter, r *http.Request) {
|
||||||
if (r.Method == "POST") {
|
if (r.Method == "POST") {
|
||||||
info := Info{
|
info := Info{
|
||||||
Ip: r.RemoteAddr,
|
Ip: r.RemoteAddr,
|
||||||
Random: Rand64(),
|
Random: rand.Int63(),
|
||||||
TimeStamp: time.Now(),
|
TimeStamp: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue