-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathexample_test.go
63 lines (57 loc) · 1.21 KB
/
example_test.go
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
59
60
61
62
63
package alluxio
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"time"
"github.com/Alluxio/alluxio-go/option"
)
func ExampleClient_download() {
fs := NewClient("localhost", 39999, time.Minute)
id, err := fs.OpenFile("/test_file", &option.OpenFile{})
if err != nil {
log.Fatal(err)
}
r, err := fs.Read(id)
if err != nil {
log.Fatal(err)
}
defer r.Close()
defer fs.Close(id)
if _, err := io.Copy(ioutil.Discard, r); err != nil {
log.Fatal(err)
}
}
func ExampleClient_exists() {
fs := NewClient("localhost", 39999, time.Minute)
ok, err := fs.Exists("/test_path", &option.Exists{})
if err != nil {
log.Fatal(err)
}
fmt.Println(ok)
}
func ExampleClient_listStatus() {
fs := NewClient("localhost", 39999, time.Minute)
fileInfos, err := fs.ListStatus("/test_path", &option.ListStatus{})
if err != nil {
log.Fatal(err)
}
for _, fileInfo := range fileInfos {
fmt.Println(fileInfo.Name)
}
}
func ExampleClient_upload() {
fs := NewClient("localhost", 39999, time.Minute)
id, err := fs.CreateFile("/test_file", &option.CreateFile{})
if err != nil {
log.Fatal(err)
}
n, err := fs.Write(id, bytes.NewBuffer(make([]byte, 1024)))
if err != nil {
log.Fatal(err)
}
defer fs.Close(id)
fmt.Println(n)
}