aboutsummaryrefslogtreecommitdiff
path: root/go/filer/operations.go
blob: 7e89b534d92b7bbf62ba0a9b3d8e133d61a9bdf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package filer

import ()

import (
	"code.google.com/p/weed-fs/go/util"
	"encoding/json"
	"errors"
	_ "fmt"
	"net/url"
	"strconv"
)

type ListFilesResult struct {
	Files []FileEntry
	Error string `json:"error,omitempty"`
}

func ListFiles(server string, directoryId DirectoryId, fileName string) (*ListFilesResult, error) {
	values := make(url.Values)
	values.Add("directoryId", strconv.Itoa(int(directoryId)))
	jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values)
	if err != nil {
		return nil, err
	}
	var ret ListFilesResult
	err = json.Unmarshal(jsonBlob, &ret)
	if err != nil {
		return nil, err
	}
	if ret.Error != "" {
		return nil, errors.New(ret.Error)
	}
	return &ret, nil
}

type ListDirectoriesResult struct {
	Directories []DirectoryEntry
	Error       string `json:"error,omitempty"`
}

func ListDirectories(server string, directoryId DirectoryId) (*ListDirectoriesResult, error) {
	values := make(url.Values)
	values.Add("directoryId", strconv.Itoa(int(directoryId)))
	jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values)
	if err != nil {
		return nil, err
	}
	var ret ListDirectoriesResult
	err = json.Unmarshal(jsonBlob, &ret)
	if err != nil {
		return nil, err
	}
	if ret.Error != "" {
		return nil, errors.New(ret.Error)
	}
	return &ret, nil
}