Open Library search API

If nothing is found on the server, returns results from open library
API. Clicking on a book imports it.
This commit is contained in:
2025-12-30 18:13:11 +01:00
parent 4d901ccc02
commit 1bb841332c
18 changed files with 478 additions and 57 deletions

View File

@@ -0,0 +1,29 @@
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
}