-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathexample_test.go
More file actions
42 lines (33 loc) · 815 Bytes
/
example_test.go
File metadata and controls
42 lines (33 loc) · 815 Bytes
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
package httpsfv
import (
"bytes"
"fmt"
"log"
"net/http"
)
func ExampleUnmarshalList() {
h := http.Header{}
h.Add("Preload", `"/member/*/author", "/member/*/comments"`)
v, err := UnmarshalList(h["Preload"])
if err != nil {
log.Fatalln("error: ", err)
}
fmt.Println("authors selector: ", v[0].(Item).Value)
fmt.Println("comments selector: ", v[1].(Item).Value)
// Output:
// authors selector: /member/*/author
// comments selector: /member/*/comments
}
func ExampleMarshal() {
p := List{NewItem("/member/*/author"), NewItem("/member/*/comments")}
v, err := Marshal(p)
if err != nil {
log.Fatalln("error: ", err)
}
h := http.Header{}
h.Set("Preload", v)
b := new(bytes.Buffer)
_ = h.Write(b)
fmt.Println(b.String())
// Output: Preload: "/member/*/author", "/member/*/comments"
}