-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_example_test.go
54 lines (45 loc) · 1016 Bytes
/
client_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
package jot_test
import (
"bytes"
"fmt"
"log"
"net/http"
"strings"
"github.com/jotfs/jot"
)
func ExampleNew() {
jot.New("http://example.com:6777", http.DefaultClient, nil)
}
func ExampleNew_options() {
jot.New("https://jotfs.example.com", http.DefaultClient, &jot.Options{
Compression: jot.CompressNone,
})
}
func ExampleClient_Upload() {
client, err := jot.New("http://localhost:6777", http.DefaultClient, nil)
if err != nil {
log.Fatal(err)
}
r := strings.NewReader("Hello World!")
fileID, err := client.Upload(r, "/notes/today.txt")
if err != nil {
log.Fatal(err)
}
fmt.Printf("fileID = %x\n", fileID.Marshal())
}
func ExampleClient_Download() {
client, err := jot.New("http://localhost:6777", http.DefaultClient, nil)
if err != nil {
log.Fatal(err)
}
r := strings.NewReader("Hello World!")
fileID, err := client.Upload(r, "/notes/today.txt")
if err != nil {
log.Fatal(err)
}
var w bytes.Buffer
err = client.Download(fileID, &w)
if err != nil {
log.Fatal(err)
}
}