httpapi

package
v0.0.0-...-8647d1c Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 37 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 httpapi serves the RoNote HTTP API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(o Options) http.Handler

New returns the API handler: /healthz, /readyz and the routes of api/openapi.yaml under /api/v1.

func NewServer

func NewServer(h http.Handler, logger *slog.Logger) *http.Server

NewServer returns an http.Server for h with explicit timeouts and limits. Errors from the server itself are logged through logger.

Types

type Accounts

type Accounts interface {
	SignIn(ctx context.Context, id store.Identity) (store.User, error)
	GetAccount(ctx context.Context, user uuid.UUID, provider string) (store.Account, error)
	CreateSession(ctx context.Context, hash []byte, user uuid.UUID, lifetime time.Duration) error
	GetSession(ctx context.Context, hash []byte, idle, touch time.Duration) (store.Session, error)
	TouchSession(ctx context.Context, hash []byte) error
	DeleteSession(ctx context.Context, hash []byte) error
	DeleteUserSessions(ctx context.Context, user uuid.UUID) error
	DeleteUser(ctx context.Context, user uuid.UUID) error
}

Accounts is where sign-in keeps users and sessions. *store.Store implements it; it is an interface so handler tests can run without a database.

type Backend

type Backend interface {
	Request(ctx context.Context, owner uuid.UUID, rawURL string) (importer.Requested, error)
	RequestPDF(ctx context.Context, owner uuid.UUID, filename string, file io.ReadSeeker, size int64) (importer.Requested, error)
	Original(ctx context.Context, owner, id uuid.UUID) (string, *blob.Object, error)
	GetImport(ctx context.Context, owner, id uuid.UUID) (store.Import, error)
	GetDocument(ctx context.Context, owner, id uuid.UUID) (store.Document, error)
	DocumentExtraction(ctx context.Context, owner, id uuid.UUID) (*ir.Doc, error)
	SaveDocument(ctx context.Context, owner, id uuid.UUID, content *doccontent.Doc, version int) (int, error)
	DeleteDocument(ctx context.Context, owner, id uuid.UUID) ([]uuid.UUID, error)
	ListDocuments(ctx context.Context, owner uuid.UUID, after *store.DocumentCursor, limit int) ([]store.DocumentSummary, error)
	ResolveDocuments(ctx context.Context, owner uuid.UUID, urls []string) (map[string]uuid.UUID, error)
	ListAnnotations(ctx context.Context, owner, document uuid.UUID) ([]store.Annotation, error)
	CreateAnnotation(ctx context.Context, owner, document uuid.UUID, a store.NewAnnotation) (store.Annotation, error)
	UpdateAnnotation(ctx context.Context, owner, id uuid.UUID, change store.AnnotationChange) (store.Annotation, error)
	ReanchorAnnotations(ctx context.Context, owner, document uuid.UUID, moves []store.Reanchor) ([]store.Annotation, error)
	DeleteAnnotation(ctx context.Context, owner, id uuid.UUID) error
}

Backend is what /api/v1 reads and writes through: the import service and the store, scoped to the signed-in user. It is an interface so handler tests can run without a database.

type Events

type Events interface {
	Subscribe(id uuid.UUID) (<-chan events.Event, func())
}

Events is where event streams hear about status changes. *events.Broker implements it; it is an interface so handler tests can drive it.

type Limits

type Limits struct {
	// APIPerMinute counts one user's requests, the import event stream
	// excepted.
	APIPerMinute int
	// AuthPerMinute counts one IP's requests to /api/v1/auth.
	AuthPerMinute int
}

Limits are the API's rate limits; zero means none (docs/adr/0010-sign-in-and-sessions.md).

type Options

type Options struct {
	// Logger logs requests and panics.
	Logger *slog.Logger
	// DB answers /readyz.
	DB Pinger
	// Backend serves /api/v1.
	Backend Backend
	// Events feeds the import event streams.
	Events Events
	// Done closes when the server begins to shut down, which ends event
	// streams so the shutdown need not wait for their clients.
	Done <-chan struct{}
	// Accounts keeps users and their sessions.
	Accounts Accounts
	// Cookies carry sessions and sign-ins in progress.
	Cookies auth.Cookies
	// GitHub is where people sign in.
	GitHub auth.GitHub
	// PublicURL is RoNote's origin, the one origin trusted to send unsafe
	// requests from another site.
	PublicURL string
	// Limits are the rate limits.
	Limits Limits
	// TrustedProxies may say, in X-Forwarded-For, which client a request
	// is from.
	TrustedProxies Proxies
	// Searcher searches users' libraries; ShowScores puts each result's
	// scores in the answer, in dev and test.
	Searcher   Searcher
	ShowScores bool
	// Chat answers questions over a user's library; nil, or turned off,
	// answers its routes with 503.
	Chat *chat.Service
}

Options are what the API handler serves with.

type Pinger

type Pinger interface {
	Ping(ctx context.Context) error
}

Pinger reports whether the database answers. *pgxpool.Pool implements it.

type Proxies

type Proxies []netip.Prefix

Proxies are the networks whose X-Forwarded-For the API trusts: Caddy's in production, none by default (docs/adr/0014-production-topology.md).

type Searcher

type Searcher interface {
	Search(ctx context.Context, r search.Request) (search.Results, error)
}

Searcher searches a user's library. *search.Searcher implements it; it is an interface so handler tests can run without a database.

Directories

Path Synopsis
Package gen provides primitives to interact with the openapi HTTP API.
Package gen provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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