-
Notifications
You must be signed in to change notification settings - Fork 1
/
json.go
101 lines (86 loc) · 2.25 KB
/
json.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package crossref
import (
"fmt"
"strings"
)
type queryJSON struct {
Status string `json:"status"`
Type string `json:"message-type"`
Version string `json:"message-version"`
Message *queryMessageJSON `json:"message"`
}
type queryMessageJSON struct {
Query map[string]interface{} `json:"query"`
Facets map[string]interface{} `json:"facets"`
TotalResults int `json:"total-results"`
Items []*Work `json:"items"`
ItemsPerPage int `json:"items-per-page"`
}
type doiJSON struct {
Status string `json:"status"`
Type string `json:"message-type"`
Version string `json:"message-version"`
Work *Work `json:"message"`
}
// Contributor saves the name of the author in First Last name.
type Contributor struct {
// First is the given name of the contributor.
First string `json:"given"`
// Last is the family name of the contributor.
Last string `json:"family"`
}
// String implements the Stringer interface.
func (c *Contributor) String() string {
return c.Last + ", " + c.First
}
// Work is the processed JSON for direct access to the information.
type Work struct {
Type string
DOI string `json:"DOI"`
Titles []string `json:"title"`
Title string
BookTitles []string `json:"container-title"`
BookTitle string
Authors []*Contributor `json:"author"`
Editors []*Contributor `json:"editor"`
Issued *dateParts `json:"issued"`
Date string
Publisher string `json:"publisher"`
Issue string `json:"issue"`
Volume string `json:"volume"`
Pages string `json:"page"`
ISSNs []string `json:"ISSN"`
ISSN string
ISBNs []string `json:"ISBN"`
ISBN string
Abstract string `json:"abstract"`
}
func (w *Work) parse() {
if w.Titles != nil {
if len(w.Titles) > 0 {
w.Title = w.Titles[0]
}
}
if w.BookTitles != nil {
if len(w.BookTitles) > 0 {
w.BookTitle = w.BookTitles[0]
}
}
if w.ISBNs != nil {
if len(w.ISBNs) > 0 {
w.ISBN = w.ISBNs[0]
}
}
if w.ISSNs != nil {
if len(w.ISSNs) > 0 {
w.ISSN = w.ISSNs[0]
}
}
for _, v := range w.Issued.Parts[0] {
w.Date = fmt.Sprintf("%s%d-", w.Date, v)
}
w.Date = strings.TrimRight(w.Date, "-")
}
type dateParts struct {
Parts [][]int `json:"date-parts"`
}