-
Notifications
You must be signed in to change notification settings - Fork 1
/
examples_test.go
58 lines (50 loc) · 1.24 KB
/
examples_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
package crossref_test
import (
"fmt"
"github.com/cgxeiji/crossref"
)
func ExampleClient_Query() {
// Search for a work on Crossref.
works, err := client.Query("Slow Robots for Unobtrusive Posture Correction")
if err != nil {
panic(err)
}
work := works[0]
fmt.Println(work.DOI)
// If no works can be found, Query returns with ErrZeroWorks error.
_, err = client.Query("jtfiejfrlsadaksljablkjoifajebwoijffal")
switch err {
case crossref.ErrZeroWorks:
fmt.Println("No works found")
case crossref.ErrEmptyQuery:
fmt.Println("An empty query was requested")
case nil:
default:
panic(err)
}
// Output:
// 10.1145/3290605.3300843
// No works found
}
func ExampleClient_DOI() {
// Search for a DOI metadata on Crossref.
work, err := client.DOI("10.1145/3290605.3300843")
if err != nil {
panic(err)
}
fmt.Println(work.Title)
// If no works can be found, DOI returns with ErrZeroWorks error.
_, err = client.DOI("10.1145/3290605.330084") // deleted the last digit
switch err {
case crossref.ErrZeroWorks:
fmt.Println("No work found")
case crossref.ErrEmptyQuery:
fmt.Println("An empty DOI was requested")
case nil:
default:
panic(err)
}
// Output:
// Slow Robots for Unobtrusive Posture Correction
// No work found
}