web

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: 0BSD Imports: 28 Imported by: 0

Documentation

Overview

Package web provides the toga web UI for browsing cached modules and viewing logs.

templ: version: v0.3.1001

Index

Constants

View Source
const DefaultPageSize = 50

DefaultPageSize is the number of modules per page.

Variables

This section is empty.

Functions

func StaticFS

func StaticFS() http.FileSystem

StaticFS returns an http.FileSystem serving the embedded static assets.

Types

type AzureLister

type AzureLister struct {
	Client    *azblob.Client
	Container string
}

AzureLister implements Lister for Azure Blob Storage backends.

func (*AzureLister) DeleteModule

func (a *AzureLister) DeleteModule(ctx context.Context, modulePath, version string) error

DeleteModule removes cached files for a module and optional version.

func (*AzureLister) GetFile

func (a *AzureLister) GetFile(ctx context.Context, name string) (io.ReadCloser, error)

GetFile retrieves a single cached file by name.

func (*AzureLister) ListFiles

func (a *AzureLister) ListFiles(ctx context.Context, modulePath string) ([]FileEntry, error)

ListFiles lists all cached files for a module path.

func (*AzureLister) ListModules

func (a *AzureLister) ListModules(ctx context.Context, cursor, query string, limit int) (*ModulePage, error)

ListModules returns a paginated list of cached modules from the backend.

type DiskLister

type DiskLister struct {
	Root string
}

DiskLister implements Lister for filesystem-based caches.

func (*DiskLister) DeleteModule

func (d *DiskLister) DeleteModule(_ context.Context, modulePath, version string) error

DeleteModule removes cached files for a module path and optional version.

func (*DiskLister) GetFile

func (d *DiskLister) GetFile(_ context.Context, name string) (io.ReadCloser, error)

GetFile returns a cached file by its cache-relative name.

func (*DiskLister) ListFiles

func (d *DiskLister) ListFiles(_ context.Context, modulePath string) ([]FileEntry, error)

ListFiles returns all cached files for a module path.

func (*DiskLister) ListModules

func (d *DiskLister) ListModules(ctx context.Context, cursor, query string, limit int) (*ModulePage, error)

ListModules walks the cache directory with efficient pagination. Instead of walking the entire tree, it:

  1. Collects only module paths (directories containing @v/).
  2. Skips directory subtrees that sort before the cursor.
  3. Stops walking once limit+1 modules are found (for hasMore detection).
  4. Only stats files for the modules in the returned page.

type FetchResult

type FetchResult struct {
	Module string
	Err    error
}

FetchResult holds the outcome of fetching a single module.

type FileEntry

type FileEntry struct {
	Name    string
	Size    int64
	ModTime time.Time
}

FileEntry represents a file in the cache for display.

type GCSLister

type GCSLister struct {
	Client *storage.Client
	Bucket string
}

GCSLister implements Lister for Google Cloud Storage backends.

func (*GCSLister) DeleteModule

func (g *GCSLister) DeleteModule(ctx context.Context, modulePath, version string) error

DeleteModule removes cached files for a module and optional version.

func (*GCSLister) GetFile

func (g *GCSLister) GetFile(ctx context.Context, name string) (io.ReadCloser, error)

GetFile retrieves a single cached file by name.

func (*GCSLister) ListFiles

func (g *GCSLister) ListFiles(ctx context.Context, modulePath string) ([]FileEntry, error)

ListFiles lists all cached files for a module path.

func (*GCSLister) ListModules

func (g *GCSLister) ListModules(ctx context.Context, cursor, query string, limit int) (*ModulePage, error)

ListModules returns a paginated list of cached modules from the backend.

type Handler

type Handler struct {
	Lister  Lister
	Fetcher *goproxy.GoFetcher
	Cacher  goproxy.Cacher
	Logger  *slog.Logger
	Prefix  string // URL prefix, e.g. "/-/ui"
}

Handler serves the toga web UI.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes UI requests.

type Lister

type Lister interface {
	// ListModules returns a paginated list of cached modules.
	// cursor is the module path to start after (empty for first page).
	// query filters by substring match (empty for all).
	// limit is max results to return.
	ListModules(ctx context.Context, cursor, query string, limit int) (*ModulePage, error)
	ListFiles(ctx context.Context, modulePath string) ([]FileEntry, error)
	GetFile(ctx context.Context, name string) (io.ReadCloser, error)
	DeleteModule(ctx context.Context, modulePath, version string) error
}

Lister can enumerate cached modules. Implemented per storage backend.

type Module

type Module struct {
	Path     string
	Versions []Version
}

Module represents a cached Go module with its available versions.

type ModulePage

type ModulePage struct {
	Modules    []Module
	NextCursor string // empty if no more results
	Total      int    // total matching modules (-1 if unknown)
}

ModulePage is a paginated result set of modules.

type ObjectStoreLister

type ObjectStoreLister struct {
	Client *minio.Client
	Bucket string
}

ObjectStoreLister implements Lister for S3/MinIO backends using the minio-go client. It uses ListObjects with delimiter to paginate efficiently server-side.

func (*ObjectStoreLister) DeleteModule

func (o *ObjectStoreLister) DeleteModule(ctx context.Context, modulePath, version string) error

DeleteModule removes cached files for a module from the object store.

func (*ObjectStoreLister) GetFile

func (o *ObjectStoreLister) GetFile(ctx context.Context, name string) (io.ReadCloser, error)

GetFile retrieves a single object from the store.

func (*ObjectStoreLister) ListFiles

func (o *ObjectStoreLister) ListFiles(ctx context.Context, modulePath string) ([]FileEntry, error)

ListFiles lists all objects under module/@v/. ListFiles lists all objects under a module's version prefix.

func (*ObjectStoreLister) ListModules

func (o *ObjectStoreLister) ListModules(ctx context.Context, cursor, query string, limit int) (*ModulePage, error)

ListModules uses S3 ListObjects to enumerate module paths. Since S3 keys are flat (module/@v/version.ext), we list with prefix="" and look for keys containing versionPrefix to extract module paths. For large buckets, this streams results instead of loading all keys into memory. ListModules returns a paginated list of cached modules from the object store.

type ProgressFunc

type ProgressFunc func(FetchResult)

ProgressFunc is called after each module is fetched during recursive fetch.

type Version

type Version struct {
	Version string
	Time    time.Time
	HasInfo bool
	HasMod  bool
	HasZip  bool
	Size    int64
}

Version represents a cached module version.

Directories

Path Synopsis
Command fetch-assets downloads htmx, Alpine.js, Pico CSS, and highlight.js into internal/web/static/ for embedding into the toga binary.
Command fetch-assets downloads htmx, Alpine.js, Pico CSS, and highlight.js into internal/web/static/ for embedding into the toga binary.

Jump to

Keyboard shortcuts

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