コード例 #1
0
ファイル: filetree.go プロジェクト: t3rm1n4l/camlistore
func (fth *FileTreeHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	if req.Method != "GET" && req.Method != "HEAD" {
		http.Error(rw, "Invalid method", 400)
		return
	}
	ret := make(map[string]interface{})
	defer httputil.ReturnJSON(rw, ret)

	de, err := schema.NewDirectoryEntryFromBlobRef(fth.storageSeekFetcher(), fth.file)
	dir, err := de.Directory()
	if err != nil {
		http.Error(rw, "Error reading directory", 500)
		log.Printf("Error reading directory from blobref %s: %v\n", fth.file, err)
		return
	}
	entries, err := dir.Readdir(-1)
	if err != nil {
		http.Error(rw, "Error reading directory", 500)
		log.Printf("reading dir from blobref %s: %v\n", fth.file, err)
		return
	}
	children := make([]map[string]interface{}, 0)
	for _, v := range entries {
		child := map[string]interface{}{
			"name":    v.FileName(),
			"type":    v.CamliType(),
			"blobRef": v.BlobRef(),
		}
		children = append(children, child)
	}
	ret["children"] = children
}
コード例 #2
0
ファイル: filetree.go プロジェクト: rfistman/camlistore
func (fth *FileTreeHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	if req.Method != "GET" && req.Method != "HEAD" {
		http.Error(rw, "Invalid method", 400)
		return
	}

	de, err := schema.NewDirectoryEntryFromBlobRef(fth.Fetcher, fth.file)
	if err != nil {
		http.Error(rw, "Error reading directory", 500)
		log.Printf("Error reading directory from blobref %s: %v\n", fth.file, err)
		return
	}
	dir, err := de.Directory()
	if err != nil {
		http.Error(rw, "Error reading directory", 500)
		log.Printf("Error reading directory from blobref %s: %v\n", fth.file, err)
		return
	}
	entries, err := dir.Readdir(-1)
	if err != nil {
		http.Error(rw, "Error reading directory", 500)
		log.Printf("reading dir from blobref %s: %v\n", fth.file, err)
		return
	}

	var ret = FileTreeResponse{
		Children: make([]FileTreeNode, 0, len(entries)),
	}
	for _, v := range entries {
		ret.Children = append(ret.Children, FileTreeNode{
			Name:    v.FileName(),
			Type:    v.CamliType(),
			BlobRef: v.BlobRef(),
		})
	}
	httputil.ReturnJSON(rw, ret)
}