From 1af881a3f243e3e89c3db7fe33cb9efd8bfbff30 Mon Sep 17 00:00:00 2001 From: mpl Date: Wed, 13 May 2015 15:35:50 +0200 Subject: [PATCH] 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 --- pkg/server/filetree.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/server/filetree.go b/pkg/server/filetree.go index b0dbbd338..daef6b35a 100644 --- a/pkg/server/filetree.go +++ b/pkg/server/filetree.go @@ -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) }