openbd

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package openbd is the library behind the openbd command line: the HTTP client, request shaping, and typed data models for the OpenBD API (https://api.openbd.jp), the Japanese book database with 1.9M ISBNs.

No API key is required. The Client paces requests, sets a real User-Agent, and retries transient failures (429 and 5xx).

Index

Constants

View Source
const Host = "api.openbd.jp"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	ISBN      string `kit:"id" json:"isbn"`
	Title     string `json:"title"`
	Author    string `json:"author"`
	Publisher string `json:"publisher"`
	PubDate   string `json:"pubdate"`
	Series    string `json:"series,omitempty"`
	Volume    string `json:"volume,omitempty"`
	Cover     string `json:"cover,omitempty"`
}

Book holds the public data about a single book.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the OpenBD API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given configuration.

func (*Client) GetBooks

func (c *Client) GetBooks(ctx context.Context, isbns string) ([]Book, error)

GetBooks fetches books by one or more ISBNs (comma-separated). The API returns null for ISBNs not found; those are skipped.

func (*Client) GetCoverage

func (c *Client) GetCoverage(ctx context.Context) (*Coverage, error)

GetCoverage returns the count of ISBNs covered by OpenBD.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Coverage

type Coverage struct {
	Count int `json:"count"`
}

Coverage holds the count of ISBNs covered by OpenBD.

type Domain

type Domain struct{}

Domain is the openbd driver.

func (Domain) Classify

func (Domain) Classify(input string) (string, string, error)

Classify turns any input into (type, id). Everything is a book.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, hostnames, and binary identity.

func (Domain) Locate

func (Domain) Locate(t, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL