diff options
Diffstat (limited to 'go/filer')
| -rw-r--r-- | go/filer/directory.go | 4 | ||||
| -rw-r--r-- | go/filer/filer.go | 4 | ||||
| -rw-r--r-- | go/filer/operations.go | 58 |
3 files changed, 63 insertions, 3 deletions
diff --git a/go/filer/directory.go b/go/filer/directory.go index 2eefed9c1..956a2f504 100644 --- a/go/filer/directory.go +++ b/go/filer/directory.go @@ -11,8 +11,10 @@ type DirectoryEntry struct { type DirectoryManager interface { FindDirectory(dirPath string) (DirectoryId, error) - ListDirectories(dirPath string) (dirNames []DirectoryEntry, err error) + ListDirectories(dirPath string) (dirs []DirectoryEntry, err error) MakeDirectory(currentDirPath string, dirName string) (DirectoryId, error) MoveUnderDirectory(oldDirPath string, newParentDirPath string) error DeleteDirectory(dirPath string) error + //functions used by FUSE + FindDirectoryById(DirectoryId, error) } diff --git a/go/filer/filer.go b/go/filer/filer.go index a42d9ed8c..8d2da901b 100644 --- a/go/filer/filer.go +++ b/go/filer/filer.go @@ -5,8 +5,8 @@ import () type FileId string //file id on weedfs type FileEntry struct { - Name string //file name without path - Id FileId + Name string `json:"name,omitempty"` //file name without path + Id FileId `json:"fid,omitempty"` } type Filer interface { 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 +} |
