Documentation
¶
Overview ¶
Package kegg is the library behind the kegg command line: the HTTP client, request shaping, and the typed data models for the KEGG REST API (rest.kegg.jp).
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load. KEGG returns plain TSV text, not JSON; all parsing converts tab-separated lines into the typed records below.
Index ¶
- Constants
- type Client
- func (c *Client) FindEntries(ctx context.Context, db, query string) ([]*Entry, error)
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetCompound(ctx context.Context, id string) (*Compound, error)
- func (c *Client) GetEntry(ctx context.Context, id string) ([]byte, error)
- func (c *Client) ListCompounds(ctx context.Context) ([]*Compound, error)
- func (c *Client) ListPathways(ctx context.Context) ([]*Pathway, error)
- type Compound
- type Config
- type Domain
- type Entry
- type Gene
- type Pathway
Constants ¶
const BaseURL = "https://rest.kegg.jp"
BaseURL is the root every request is built from.
const DefaultUserAgent = "kegg-cli/dev (+https://github.com/tamnd/kegg-cli)"
DefaultUserAgent identifies the client to KEGG. A real, honest User-Agent is both polite and the thing most likely to keep you unblocked.
const Host = "rest.kegg.jp"
Host is the canonical homepage used for URI driver host matching.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
BaseURL string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to the KEGG REST API over HTTP.
func (*Client) FindEntries ¶
FindEntries calls /find/<db>/<query> and returns the raw Entry records. db is one of: compound, drug, pathway, genes, disease.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.
func (*Client) GetCompound ¶
GetCompound calls /get/<id> and parses the ENTRY, NAME, and FORMULA sections into a Compound.
func (*Client) GetEntry ¶
GetEntry calls /get/<id> and returns the raw flat-file text. KEGG flat files are structured text (ENTRY / NAME / FORMULA / etc sections), not JSON. The caller can parse the sections it needs; we return the whole body so callers are not limited by what we pre-parse.
func (*Client) ListCompounds ¶
ListCompounds calls /list/compound and returns all compound stubs.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration // minimum gap between requests
Timeout time.Duration
Retries int
}
Config holds the tunable knobs for the client. Values of zero mean "use the default".
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the recommended defaults for the KEGG free API: 300 ms rate limit (polite), 15 s timeout, 3 retries.
type Domain ¶
type Domain struct{}
Domain is the KEGG driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type Entry ¶
Entry is the generic record returned by the /find endpoint: an id and zero or more semicolon-separated names.