-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbook.go
More file actions
47 lines (43 loc) · 846 Bytes
/
Copy pathbook.go
File metadata and controls
47 lines (43 loc) · 846 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
43
44
45
46
47
package zlib
func (c *Client) FetchBookDetails(ids []string) map[string]Book {
type entry struct {
id string
book Book
}
ch := make(chan entry, len(ids))
for _, id := range ids {
go func(id string) {
book, err := c.FetchBook(id)
if err != nil {
ch <- entry{id: id}
return
}
ch <- entry{id: id, book: book}
}(id)
}
out := make(map[string]Book, len(ids))
for range ids {
e := <-ch
out[e.id] = e.book
}
return out
}
func (c *Client) FetchBook(id string) (Book, error) {
if !c.loggedIn {
return Book{}, ErrNotLoggedIn
}
if id == "" {
return Book{}, ErrNoID
}
bookURL := BuildBookURL(c.domain, id)
html, err := c.get(bookURL)
if err != nil {
return Book{}, err
}
book, err := parseBookDetail(html, c.domain)
if err != nil {
return Book{}, err
}
book.URL = bookURL
return book, nil
}