refactoring

This commit is contained in:
Chris Lu
2012-09-21 01:30:31 -07:00
parent 77c0de914a
commit d056c622bf

View File

@@ -139,11 +139,9 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
writeJson(w, r, ne) writeJson(w, r, ne)
} else { } else {
ret := store.Write(volumeId, needle) ret := store.Write(volumeId, needle)
if ret > 0 || !store.HasVolume(volumeId){ //send to other replica locations if ret > 0 || !store.HasVolume(volumeId) { //send to other replica locations
if r.FormValue("type") != "standard" { if r.FormValue("type") != "standard" {
waitTime, err := strconv.Atoi(r.FormValue("wait")) if lookupResult, lookupErr := operation.Lookup(*server, volumeId); lookupErr == nil {
lookupResult, lookupErr := operation.Lookup(*server, volumeId)
if lookupErr == nil {
sendFunc := func(background bool) { sendFunc := func(background bool) {
postContentFunc := func(location operation.Location) bool { postContentFunc := func(location operation.Location) bool {
operation.Upload("http://"+location.PublicUrl+r.URL.Path+"?type=standard", filename, bytes.NewReader(needle.Data)) operation.Upload("http://"+location.PublicUrl+r.URL.Path+"?type=standard", filename, bytes.NewReader(needle.Data))
@@ -159,6 +157,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
} }
waitTime, err := strconv.Atoi(r.FormValue("wait"))
sendFunc(err == nil && waitTime > 0) sendFunc(err == nil && waitTime > 0)
} else { } else {
log.Println("Failed to lookup for", volumeId, lookupErr.Error()) log.Println("Failed to lookup for", volumeId, lookupErr.Error())