web

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: BSD-3-Clause Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownSearchType = errors.New("unknown search type")

ErrUnknownSearchType is returned by SearchType when the type slug is not a recognized searchable entity type.

View Source
var StaticFS, _ = fs.Sub(staticFiles, "static")

StaticFS provides access to embedded static files (htmx.min.js, etc.) with the "static/" prefix stripped so files are served at their base names.

Functions

This section is empty.

Types

type CompareInput

type CompareInput struct {
	// ASN1 is the first network's Autonomous System Number.
	ASN1 int
	// ASN2 is the second network's Autonomous System Number.
	ASN2 int
	// ViewMode is "shared" (default) or "full".
	ViewMode string
}

CompareInput holds the parameters for a network comparison.

type CompareService

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

CompareService compares two networks' presences across IXPs, facilities, and campuses.

func NewCompareService

func NewCompareService(client *ent.Client) *CompareService

NewCompareService creates a CompareService backed by the given ent client.

func (*CompareService) Compare

Compare loads both networks' presences and computes set intersections to find shared IXPs, facilities, and campuses.

type Handler

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

Handler serves web UI pages.

func NewHandler

func NewHandler(in NewHandlerInput) *Handler

NewHandler creates a web UI handler with integrated search and compare services. AuthMode and PublicTier are captured at construction and surface on /ui/about. The input uses named fields so callers cannot transpose them.

func (*Handler) Register

func (h *Handler) Register(mux *http.ServeMux)

Register mounts web UI routes on the given mux. Static assets are served from embedded files at /static/. UI pages are served under the /ui/ prefix. A single wildcard pattern dispatches all /ui/ paths internally, following the pdbcompat handler pattern.

type NewHandlerInput added in v1.14.0

type NewHandlerInput struct {
	Client     *ent.Client
	DB         *sql.DB
	AuthMode   string
	PublicTier privctx.Tier
}

NewHandlerInput configures a web Handler. Client is required; DB may be nil for tests that do not exercise the sync-status table. AuthMode and PublicTier feed the /ui/about Privacy & Sync section. When AuthMode is empty, the renderer falls back to "anonymous"; when PublicTier is the zero value (TierPublic), no override flag is shown.

type PageContent

type PageContent struct {
	Title       string
	Kind        PageKind // Kind routes the special pages in terminal/JSON modes (zero value = ordinary page).
	Description string   // Description feeds the meta description / og:description tags when non-empty.
	Canonical   string   // Canonical feeds the rel=canonical link / og:url tags when non-empty.
	Content     templ.Component
	Data        any       // Raw data struct for terminal/JSON rendering. Nil for pages without entity data.
	Freshness   time.Time // Freshness is the last successful sync time for terminal footer display.
	Status      int       // HTTP status (0 means 200). Committed by renderPage AFTER headers — WriteHeader first drops Vary/Content-Type.
	NeedsMap    bool      // NeedsMap emits the Leaflet/markercluster head includes; set only on pages that render a MapContainer.
}

PageContent holds the title and body component for a page render. Defined to avoid >2 non-ctx arguments in renderPage.

type PageKind added in v1.23.0

type PageKind int

PageKind identifies the special pages renderPage must format differently in terminal/JSON modes. It exists so that dispatch keys on an explicit field: "Home" and "Not Found" are legal entity names, so switching on Title would misroute a network that happens to carry one of those names.

const (
	// KindEntity is the default: an ordinary data-bearing page.
	KindEntity PageKind = iota
	// KindHome is the homepage; terminal mode renders the help text.
	KindHome
	// KindNotFound is the styled 404 page.
	KindNotFound
	// KindServerError is the styled 500 page.
	KindServerError
)

type SearchHit

type SearchHit struct {
	// ID is the entity's database identifier.
	ID int
	// Name is the entity's display name.
	Name string
	// Country is the ISO 3166-1 alpha-2 code; empty if not available.
	Country string
	// City is the city name; empty if not available.
	City string
	// ASN is the AS number; 0 if not applicable (non-network entity).
	ASN int
	// DetailURL is the path to the entity's detail page (e.g. "/ui/asn/13335").
	DetailURL string
}

SearchHit represents a single search result with display-ready fields.

type SearchService

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

SearchService provides search across all 6 PeeringDB entity types.

func NewSearchService

func NewSearchService(client *ent.Client) *SearchService

NewSearchService creates a SearchService backed by the given ent client.

func (*SearchService) Search

func (s *SearchService) Search(ctx context.Context, query string) ([]TypeResult, error)

Search queries all 6 entity types in parallel for the given search term. Returns only types with matches, sorted in canonical type order. Queries under 2 characters (after trimming) return an empty slice.

func (*SearchService) SearchType added in v1.20.0

SearchType returns one page of matches for a single entity type, backing the "view all" results page. It returns ErrUnknownSearchType when the slug is not a recognized searchable type; queries under 2 characters yield an empty page.

type SearchTypeInput added in v1.20.0

type SearchTypeInput struct {
	// Query is the raw search term.
	Query string
	// TypeSlug selects the entity type (e.g. "net", "fac").
	TypeSlug string
	// Offset is the number of leading matches to skip (>= 0).
	Offset int
	// Limit is the page size; values < 1 default to pageSize.
	Limit int
}

SearchTypeInput parameterizes a single-type paginated search for the "view all" results page. The context is passed separately to SearchType.

type SearchTypeResult added in v1.20.0

type SearchTypeResult struct {
	// TypeName is the human-readable plural name (e.g. "Networks").
	TypeName string
	// TypeSlug is the short identifier used in URLs (e.g. "net").
	TypeSlug string
	// AccentColor is the Tailwind color name for visual grouping.
	AccentColor string
	// Hits holds this page's matching entities.
	Hits []SearchHit
	// HasMore indicates whether matches exist beyond this page.
	HasMore bool
	// Total is the exact number of matches across all pages.
	Total int
}

SearchTypeResult holds one page of results for a single entity type.

type TypeResult

type TypeResult struct {
	// TypeName is the human-readable plural name (e.g. "Networks", "IXPs").
	TypeName string
	// TypeSlug is the short identifier used in URLs (e.g. "net", "ix").
	TypeSlug string
	// AccentColor is the Tailwind color name for visual grouping (e.g. "emerald", "sky").
	AccentColor string
	// Results holds up to displayLimit matching entities.
	Results []SearchHit
	// HasMore indicates whether additional matches exist beyond the displayed results.
	HasMore bool
	// Total is the exact number of matches across all pages. It equals
	// len(Results) when HasMore is false; when HasMore is true it is the full
	// count (so the "view all" link can show the real total).
	Total int
}

TypeResult groups search hits for a single entity type with metadata for display.

Directories

Path Synopsis
templ: version: v0.3.1020
templ: version: v0.3.1020
Package termrender provides terminal client detection and ANSI text rendering for serving styled text responses to CLI clients like curl, wget, and HTTPie.
Package termrender provides terminal client detection and ANSI text rendering for serving styled text responses to CLI clients like curl, wget, and HTTPie.

Jump to

Keyboard shortcuts

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