viewerhost

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package viewerhost fetches, verifies, caches, and serves the api-log-viewer single-page bundle at a local URL prefix.

The backend SOURCE pins (via Config wired by package config) both the viewer version and the expected SHA-256 of dist.zip. ensureCache will refuse to write anything that does not match the configured hash — the trust model is "GitHub release asset hash matches what the binary was compiled to expect, or we serve 503." There is no auto-update, no floating-latest, no fallback URL.

Operators can opt out (Enabled=false), point at a different repo or version (with a matching Sha256), or skip the fetch entirely by pointing LocalPath at an extracted dist tree (offline mode). If an operator overrides Repo or Version without supplying a matching Sha256, this package returns 503 with detail — the binary stays up so /api still serves.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled    bool   // default true; if false, Handler always 503s
	Repo       string // e.g. "2nd1st/api-log-viewer"
	Version    string // tag, e.g. "v0.1.0"
	Sha256     string // hex-encoded SHA-256 of dist.zip
	CacheDir   string // e.g. "<data_dir>/viewer-cache"
	LocalPath  string // if non-empty, skip fetch and serve from this dir
	PublicPath string // URL prefix, e.g. "/viewer"

	// ReleasesAPIBase points the dist.zip fetch at a non-GitHub
	// releases endpoint. Default empty → https://api.github.com. Set
	// to e.g. "http://gitea.homelab.lan/api/v1" to mirror viewer
	// releases on an internal Gitea (the JSON shape Gitea returns is
	// GitHub-compatible — `assets[].browser_download_url`).
	//
	// Operators who run their own artifact store can serve viewer
	// dists from there without forking the binary.
	ReleasesAPIBase string

	// ReleasesAuthToken is sent as `Authorization: token <value>` on
	// the release-metadata GET and the asset download. Empty means
	// "no auth" (public GitHub releases). Internal Gitea repos need
	// a token; the value is sensitive and should be sourced from env
	// or a secrets file (NOT committed to the YAML config).
	ReleasesAuthToken string
}

Config is the data shape Agent 3 will wire from internal/config. All fields are required when Enabled=true and LocalPath="".

type Host

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

Host is the runtime view of the viewer mount. Construct with New; query with Info; mount with Handler. It is safe for concurrent use — initState is set once during New, and the http.Handler returned by Handler is stateless beyond an immutable pointer back here.

func New

func New(ctx context.Context, cfg Config) *Host

New constructs a Host. It performs init (cache check / extract / local path stat) synchronously but never returns nil — on failure the Host reports source="error" via Info() and the Handler returns 503 with detail. Failures here do not bring down the binary.

func (*Host) Handler

func (h *Host) Handler() http.Handler

Handler returns an http.Handler that serves the viewer at cfg.PublicPath/*. On any failure mode it returns 503 with a JSON body shaped like {"error":"...","detail":"..."} — matching the rest of api-log.

func (*Host) Info

func (h *Host) Info() Info

Info returns a snapshot of the current Host state. Safe to call from any goroutine.

type Info

type Info struct {
	Enabled    bool   `json:"enabled"`
	Repo       string `json:"repo,omitempty"`
	Version    string `json:"version,omitempty"`
	Source     string `json:"source"` // "cache" | "fetched" | "local" | "disabled" | "error"
	Sha256     string `json:"sha256,omitempty"`
	Error      string `json:"error,omitempty"`
	PublicPath string `json:"public_path,omitempty"`
}

Info is the snapshot reported via Host.Info() and embedded into /healthz output. JSON tags match what the README documents.

Jump to

Keyboard shortcuts

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