renamed package, added defer ms.Close()

This commit is contained in:
Darko Luketic 2015-05-21 21:31:05 +02:00
parent 2551d12e21
commit 30d8d4d193

13
file.go
View File

@ -1,15 +1,16 @@
package blog
package file
import (
"bytes"
"github.com/gomango/auth"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"io"
"net/http"
"regexp"
"strconv"
"time"
"github.com/gomango/auth"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
var bsonRegex = regexp.MustCompile(`[a-fA-F0-9]{24}`)
@ -45,6 +46,7 @@ func (h *FileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
ms := h.options.MS.Copy()
defer ms.Close()
gfs := ms.DB(h.options.DB).GridFS(h.options.Prefix)
type File struct {
Id string `json:"id"`
@ -68,6 +70,7 @@ func (h *FileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
default:
ms := h.options.MS.Copy()
defer ms.Close()
gfs := ms.DB(h.options.DB).GridFS(h.options.Prefix)
var file *mgo.GridFile
var e error
@ -119,6 +122,7 @@ func (h *FileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// upload and insert
ms := h.options.MS.Copy()
defer ms.Close()
gfs := ms.DB(h.options.DB).GridFS(h.options.Prefix)
if !h.options.AllowDuplicate {
// No duplicate files
@ -207,6 +211,7 @@ func (h *FileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
ms := h.options.MS.Copy()
defer ms.Close()
gfs := ms.DB(h.options.DB).GridFS(h.options.Prefix)
isadmin := false