If nothing is found on the server, returns results from open library API. Clicking on a book imports it.
30 lines
800 B
Go
30 lines
800 B
Go
package openlibrary
|
|
|
|
type OpenLibrarySearchResult struct {
|
|
Books []OpenLibrarySearchBook `json:"docs"`
|
|
NumFound int `json:"numFound"`
|
|
}
|
|
|
|
type OpenLibrarySearchBook struct {
|
|
Title string `json:"title"`
|
|
Authors []string `json:"author_name"`
|
|
OpenLibraryId string `json:"cover_edition_key"`
|
|
}
|
|
|
|
func CallOpenLibrarySearch(searchterm string, limit int, offset int) (OpenLibrarySearchResult, error) {
|
|
var queryResult OpenLibrarySearchResult
|
|
u, err := computeOpenLibraryUrl("search.json")
|
|
if err != nil {
|
|
return queryResult, err
|
|
}
|
|
if limit != 0 {
|
|
addQueryParamInt(u, "limit", limit)
|
|
}
|
|
if offset != 0 {
|
|
addQueryParamInt(u, "offset", offset)
|
|
}
|
|
addQueryParam(u, "q", searchterm)
|
|
err = fetchAndParseResult(u, &queryResult)
|
|
return queryResult, err
|
|
}
|