library

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 13 Imported by: 0 modules, 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 library is where the agent reads: public-domain books from Project Gutenberg (found through its own OPDS search) and articles from Wikipedia. It fetches only from an allow-list of hosts, so nothing it reads comes from a page chosen by someone else.

Index

Constants

View Source
const (
	GutenbergURL = "https://www.gutenberg.org"
	WikipediaURL = "https://en.wikipedia.org"
)

Variables

View Source
var ErrNotFound = errors.New("nothing found")

Functions

func Passage

func Passage(text string, from, size int) (passage string, next int)

Passage returns the part of text starting at from, about size characters long, ended at a paragraph (or failing that, a sentence) break; and where the next passage starts. next == len(text) at the end.

func StripGutenberg

func StripGutenberg(text string) string

Types

type Article

type Article struct {
	Title string
	URL   string
	Text  string
}

type Book

type Book struct {
	ID      int
	Title   string
	Author  string
	TextURL string
}

type Client

type Client struct {
	Gutenberg string
	Wikipedia string
	MaxBytes  int64 // the most it downloads at once
	// contains filtered or unexported fields
}

func New

func New(gutenberg, wikipedia string) *Client

New makes a client for the given services ("" for the real ones). Both gutenberg.org hosts are allowed because it redirects books' text between them.

func (*Client) BookText

func (c *Client) BookText(ctx context.Context, b Book) (string, error)

func (*Client) FindArticle

func (c *Client) FindArticle(ctx context.Context, query string) (Article, error)

func (*Client) FindBook

func (c *Client) FindBook(ctx context.Context, query string) (Book, error)

Jump to

Keyboard shortcuts

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