openlibrary/openlibrary.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
package openlibrary
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
type CurrentBooks struct {
ReadingLogEntries []struct {
Work struct {
Title string `json:"title"`
Key string `json:"key"`
AuthorKeys []string `json:"author_keys"`
AuthorNames []string `json:"author_names"`
FirstPublishYear int `json:"first_publish_year"`
LendingEditionS interface{} `json:"lending_edition_s"`
EditionKey []string `json:"edition_key"`
CoverID int `json:"cover_id"`
CoverEditionKey string `json:"cover_edition_key"`
} `json:"work"`
LoggedEdition string `json:"logged_edition"`
LoggedDate string `json:"logged_date"`
} `json:"reading_log_entries"`
}
func GetCurrentBooks() *CurrentBooks {
cb := CurrentBooks{}
resp, err := http.Get("https://openlibrary.org/people/j3sj3sj3s/books/currently-reading.json")
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
err = json.Unmarshal(body, &cb)
if err != nil {
fmt.Println(err)
}
return &cb
}