Fix data race reported by golang 1.5
This commit is contained in:
@@ -10,7 +10,7 @@ checkgopath:
|
||||
@for mcpath in $(echo ${GOPATH} | sed 's/:/\n/g' | grep -v Godeps); do if [ ! -d ${mcpath}/src/github.com/minio/mc ]; then echo "Project not found in ${mcpath}, please follow instructions provided at https://github.com/minio/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi done
|
||||
|
||||
getdeps: checkdeps checkgopath
|
||||
@go get github.com/minio/godep && echo "Installed godep:"
|
||||
@go get github.com/tools/godep && echo "Installed godep:"
|
||||
@go get github.com/golang/lint/golint && echo "Installed golint:"
|
||||
@go get golang.org/x/tools/cmd/vet && echo "Installed vet:"
|
||||
@go get github.com/fzipp/gocyclo && echo "Installed gocyclo:"
|
||||
|
||||
@@ -22,15 +22,19 @@ import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type objectAPIHandler struct {
|
||||
lock *sync.Mutex
|
||||
bucket string
|
||||
object map[string][]byte
|
||||
}
|
||||
|
||||
func (h objectAPIHandler) getHandler(w http.ResponseWriter, r *http.Request) {
|
||||
h.lock.Lock()
|
||||
defer h.lock.Unlock()
|
||||
switch {
|
||||
case r.URL.Path == "/":
|
||||
response := []byte("<ListAllMyBucketsResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Buckets><Bucket><Name>bucket</Name><CreationDate>2015-05-20T23:05:09.230Z</CreationDate></Bucket></Buckets><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner></ListAllMyBucketsResult>")
|
||||
@@ -53,6 +57,8 @@ func (h objectAPIHandler) getHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h objectAPIHandler) headHandler(w http.ResponseWriter, r *http.Request) {
|
||||
h.lock.Lock()
|
||||
defer h.lock.Unlock()
|
||||
switch {
|
||||
case r.URL.Path == "/":
|
||||
w.WriteHeader(http.StatusOK)
|
||||
@@ -70,6 +76,8 @@ func (h objectAPIHandler) headHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h objectAPIHandler) putHandler(w http.ResponseWriter, r *http.Request) {
|
||||
h.lock.Lock()
|
||||
defer h.lock.Unlock()
|
||||
switch {
|
||||
case r.URL.Path == "/":
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"net/http/httptest"
|
||||
@@ -55,7 +56,7 @@ func (s *CmdTestSuite) SetUpSuite(c *C) {
|
||||
_, err = doConfig("generate", nil)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
objectAPI := objectAPIHandler(objectAPIHandler{bucket: "bucket", object: make(map[string][]byte)})
|
||||
objectAPI := objectAPIHandler(objectAPIHandler{lock: &sync.Mutex{}, bucket: "bucket", object: make(map[string][]byte)})
|
||||
server = httptest.NewServer(objectAPI)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user