diff --git a/file.go b/file.go index e6dda15..104bfc5 100644 --- a/file.go +++ b/file.go @@ -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