webapp

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package webapp contains deliberately small building blocks shared by the runnable web applications in cmd/. It keeps the examples dependency-free while making their database and HTTP behaviour consistent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, db *sql.DB, statements ...string) error

Apply executes schema statements one by one so error messages name the failing statement. The schemas in these examples are intentionally simple and use only TinySQL's public SQL surface.

func ContextWithTimeout

func ContextWithTimeout(parent context.Context) (context.Context, context.CancelFunc)

ContextWithTimeout returns a modest request timeout used by command apps.

func Error

func Error(w http.ResponseWriter, r *http.Request, status int, message string)

Error writes a JSON error when a request targets /api/, otherwise a plain text HTTP error. It avoids leaking implementation details from handlers.

func JSON

func JSON(w http.ResponseWriter, status int, value any)

JSON writes a JSON response. It is suitable for the compact browser APIs in the examples and intentionally does not expose internal errors itself.

func NextID

func NextID(ctx context.Context, q interface {
	QueryRowContext(context.Context, string, ...any) *sql.Row
}, table string) (int64, error)

NextID returns the next positive integral key for a fixed, trusted table name. Table names are supplied by application code, never HTTP input.

func Open

func Open(ctx context.Context, dsn string) (*sql.DB, error)

Open opens a TinySQL database and verifies it before returning. Callers can pass mem:// for ephemeral data or file:path.db?autosave=1 for persistence.

func SecurityHeaders

func SecurityHeaders(next http.Handler) http.Handler

SecurityHeaders adds a compact baseline appropriate for local web tools. No third-party scripts, frames or plugin content are required by these apps.

Types

This section is empty.

Jump to

Keyboard shortcuts

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