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