Wrapper for JSON web API for Project Gutenberg ebook metadata, see here
go get https://github.com/pab-h/gotendex
The gutendex.com/books endpoint is binded by the method
func (api Api) Books() *src.Response
The book struct is
type Book struct {
Id int `json:"id"`
Title string `json:"title"`
Subjects []string `json:"subjects"`
Authors []Person `json:"authors"`
Translators []Person `json:"translators"`
Bookshelves []string `json:"bookshelves"`
Languages []string `json:"languages"`
Copyright bool `json:"copyright"`
MediaType string `json:"media_type"`
Formats map[string]string `json:"formats"`
DownloadCount int `json:"download_count"`
}
You can make a query using the method
func (api Api) QueryBooks(query *Query) *src.Response
The Query struct is
type Query struct {
AuthorYearStart int
AuthorYearEnd int
Copyright bool
Ids []int
Languages []string
MimeType string
Search string
Sort []string
Topic string
}
You can navigate the pagination using the following methods:
func (api Api) Next(response *src.Response) (*src.Response, bool)
func (api Api) Previous(response *src.Response) (*src.Response, bool)
The return bool
indicates whether you were able to continue
package main
import (
"fmt"
"github.com/pab-h/gotendex"
)
func main() {
api := gotendex.NewApi()
responseBooks := api.Books()
fmt.Println("cout:", responseBooks.Count)
for _, book := range responseBooks.Results {
fmt.Println("Id:", book.Id)
fmt.Println("Title:", book.Title)
}
}
package main
import (
"fmt"
"github.com/pab-h/gotendex"
)
func main() {
api := gotendex.NewApi()
query := gotendex.Query{
Languages: []string{"fr", "fi"},
}
responseBooks := api.QueryBooks(&query)
fmt.Println("cout:", responseBooks.Count)
for _, book := range responseBooks.Results {
fmt.Println("Id:", book.Id)
fmt.Println("Title:", book.Title)
}
}
package main
import (
"fmt"
"github.com/pab-h/gotendex"
)
func main() {
api := gotendex.NewApi()
query := gotendex.Query{
Languages: []string{"fr", "fi"},
}
responseBooks := api.QueryBooks(&query)
responseBooks, canGo := api.Next(responseBooks)
if canGo {
fmt.Println(" You can not go")
}
fmt.Println("cout:", responseBooks.Count)
for _, book := range responseBooks.Results {
fmt.Println("Id:", book.Id)
fmt.Println("Title:", book.Title)
}
}