server/filetree: do not defer standard response

Because we don't want to send it in the error case.

Address comments from
https://camlistore-review.googlesource.com/#/c/4957/2/pkg/server/filetree.go

Change-Id: I96ea90a8430299fb21038b5d7b794098c40d95b1
This commit is contained in:
mpl 2015-05-13 15:35:50 +02:00
parent 0655295771
commit 1af881a3f2
1 changed files with 5 additions and 4 deletions

View File

@ -54,9 +54,6 @@ func (fth *FileTreeHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
return
}
var ret FileTreeResponse
defer httputil.ReturnJSON(rw, &ret)
de, err := schema.NewDirectoryEntryFromBlobRef(fth.Fetcher, fth.file)
if err != nil {
http.Error(rw, "Error reading directory", 500)
@ -75,7 +72,10 @@ func (fth *FileTreeHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
log.Printf("reading dir from blobref %s: %v\n", fth.file, err)
return
}
ret.Children = make([]FileTreeNode, 0, len(entries))
var ret = FileTreeResponse{
Children: make([]FileTreeNode, 0, len(entries)),
}
for _, v := range entries {
ret.Children = append(ret.Children, FileTreeNode{
Name: v.FileName(),
@ -83,4 +83,5 @@ func (fth *FileTreeHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
BlobRef: v.BlobRef(),
})
}
httputil.ReturnJSON(rw, ret)
}