ads

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ads asks NASA's Astrophysics Data System for papers, one search a call.

ADS wants a token with every request, and limits how many requests each endpoint answers in a day. When it asks us to stop, nothing more is asked: there are no retries here, and no loops. The token is sent in a header and is in no error, ever.

Index

Constants

View Source
const Session = "ADS_SESSION"

Session is the variable that names where the token is kept: celestial-data-secrets ads-login writes it, and celestial-data ads reads it.

View Source
const TokenFile = "ads-token"

TokenFile is the name of the token's file beside the secrets' config, where it is kept when Session names nowhere.

Variables

This section is empty.

Functions

func Load

func Load(path string) (string, error)

Load reads the token Save kept in path. It refuses a link, a folder, anything but a plain file, a file anyone but its owner can read, one that holds no token, and one longer than a token.

It checks the file it opened, not the name, before it reads, and never waits on a pipe in a token's place. No error holds the token.

func NewGentle added in v0.0.4

func NewGentle(clock web.Clock, random web.Random) (*web.Gentle, error)

NewGentle is the gentle that asks ADS, on a clock, with a source of randomness for the jitter a policy with tries would use. Wrap the Doer of a search in web.Through with it, and ADS's stops and paces are the web package's, so nothing here paces or reads a Retry-After.

func Policy added in v0.0.4

func Policy() (web.Policy, error)

Policy is how ADS is asked: its own numbers, and the web package's default for any it does not name.

ADS limits requests by the day and publishes no pace, so the pace is one we picked. A request is never asked again after a failure with no word, since ADS counts each one against the day, and a search is a GET with no body, so no POST is repeated either.

func Save

func Save(token, path string) error

Save keeps a token in path, readable by its owner alone, over a token kept there before, so a search need not ask 1Password for it again.

It refuses an empty token, and a link, a folder or a file anyone else can read in the token's place. No error holds the token.

The token is written to a new file of its own beside path, then put in path's place, so a link put there later is replaced and not followed, and a write that fails leaves the token kept before as it was.

Types

type Doer

type Doer interface {
	Do(request *http.Request) (*http.Response, error)
}

Doer is what a search is sent through. An *http.Client is one.

func Resetting added in v0.0.4

func Resetting(doer Doer, clock web.Clock) Doer

Resetting is a Doer for the web package's gentle to wrap. ADS says when the day's limit resets in X-RateLimit-Reset, as seconds since 1970, and the web package reads only Retry-After.

So a 429 that has a reset ahead and no Retry-After is given one, as an HTTP date at that reset, and the gentle leaves ADS alone until then. Any other answer, and any failure to send, is given as it came.

A reset that cannot be read, or is not ahead of the clock, is left as it is, and the gentle rests as long as it rests when ADS says no time. A date that has passed is never handed on: the gentle reads such a date as no wait, and ADS is to rest here.

type Found

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

Found is what a search found.

func Search(ctx context.Context, doer Doer, token, query string,
	most int, agent string) (*Found, error)

Search asks ADS one question and gives what it found: at most so many papers, the newest first. It sends one request and does not retry. It refuses a missing token or query, and fewer than one paper, before it sends anything.

The token goes in the Authorization header and in no error. The agent is how the request names itself.

A 401 is ADS refusing the token. A 429 is ADS asking us to stop: its error is a *Stopped, for errors.As. Any other status but 200 is an error that names it.

func (*Found) Count

func (found *Found) Count() int

Count is how many papers ADS says match the query. It may be more than the papers it gave.

func (*Found) Papers

func (found *Found) Papers() []Paper

Papers are the papers ADS gave, in its order. The list is a copy.

func (*Found) Remaining

func (found *Found) Remaining() string

Remaining is how much of the day's limit ADS says is left, as it wrote it, or none when it did not say.

type Paper

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

Paper is a paper ADS found.

func (Paper) ArXiv

func (paper Paper) ArXiv() string

ArXiv is the paper's arXiv id, as the papers verb fetches by, or none when ADS knows of no copy on arXiv.

func (Paper) Authors

func (paper Paper) Authors() []string

Authors are the paper's authors, in ADS's order. The list is a copy.

func (Paper) Bibcode

func (paper Paper) Bibcode() string

Bibcode is ADS's name for the paper.

func (Paper) Title

func (paper Paper) Title() string

Title is the paper's first title, or none when ADS gave no title.

func (Paper) Year

func (paper Paper) Year() string

Year is the year the paper is from, as ADS writes it.

type Stopped

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

Stopped is ADS asking us to stop: it answered 429. It holds the time the limit resets as ADS wrote it, or none.

func (*Stopped) Error

func (stopped *Stopped) Error() string

Error says ADS asked us to stop, and until when if it said.

func (*Stopped) Reset

func (stopped *Stopped) Reset() string

Reset is when ADS says the limit resets, as it wrote it, or none.

Jump to

Keyboard shortcuts

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