diff options
| author | Chris Lu <chris.lu@gmail.com> | 2014-05-12 22:57:23 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2014-05-12 22:57:23 -0700 |
| commit | 328aa48c6a666e15033f34e072e40a6ba41c6d36 (patch) | |
| tree | 2db5635ec030d73551df3efe465ec6b7f619a9fa /go/filer/operations.go | |
| parent | 8ceaaa6c4ff53c3258a29e6233877e67ef30ef9e (diff) | |
| download | seaweedfs-328aa48c6a666e15033f34e072e40a6ba41c6d36.tar.xz seaweedfs-328aa48c6a666e15033f34e072e40a6ba41c6d36.zip | |
Can compile now. not working just yet.
Diffstat (limited to 'go/filer/operations.go')
| -rw-r--r-- | go/filer/operations.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/go/filer/operations.go b/go/filer/operations.go new file mode 100644 index 000000000..7e89b534d --- /dev/null +++ b/go/filer/operations.go @@ -0,0 +1,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 +} |
