{"modulePath":"github.com/htcondor/golang-htcondor/webapi","version":"v0.27.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package webui\n\nPackage webui provides the embedded Next.js static export. Without the embed\\_frontend build tag, no frontend is included and the Go server only handles API routes (dev mode uses a separate \\`next dev\\` process on :3000).\n\n## Constants\n\n```go\nconst (\n\tDefaultSiteName    = \"HTCondor\"\n\tDefaultSiteTagline = \"Access Point\"\n)\n```\nDefault presentation, matching what the frontend hard-codes.\n\n```go\nconst (\n\t// PrivacyPath and TermsPath are where the pages are served. They\n\t// are fixed, so that an operator who has configured a policy has\n\t// one URL to give out -- to an OAuth2 provider's review form, say\n\t// -- whether the text is served from here or lives elsewhere.\n\tPrivacyPath = \"/privacy\"\n\t// TermsPath is the other of the pair.\n\tTermsPath = \"/terms\"\n\n\t// DefaultSource is the value of HTTP_API_WEBUI_PRIVACY_FILE or\n\t// HTTP_API_WEBUI_TERMS_FILE that selects the template this package\n\t// ships, instead of a path on disk.\n\t//\n\t// Opt-in rather than a fallback for an unreadable path: a site that\n\t// meant to serve its own policy and mistyped the path should find a\n\t// 404 and a warning in the log, not a template published under its\n\t// name.\n\tDefaultSource = \"default\"\n)\n```\n\n```go\nconst CSSPath = \"/branding.css\"\n```\nCSSPath is where the site stylesheet is served, when there is one.\n\n## Functions\n\n```go\nfunc DefaultPrivacyMarkdown() []byte\n```\nDefaultPrivacyMarkdown and DefaultTermsMarkdown return the shipped templates. Copies, because the caller renders them and the embedded bytes are shared.\n\n```go\nfunc DefaultTermsMarkdown() []byte\n```\nDefaultTermsMarkdown is the shipped terms-of-use template.\n\n```go\nfunc DistFS() (fs.FS, error)\n```\nDistFS returns nil when the frontend is not embedded.\n\n```go\nfunc FindPlaceholders(doc []byte) []string\n```\nFindPlaceholders reports the template placeholders still present in a policy document.\n\nPublishing a template with \\[CONTACT EMAIL] still in it is a mistake that nobody notices, because the page renders perfectly and the operator who configured it already knows what it was meant to say. The server cannot refuse to serve the document -- an operator may have reasons, and a missing privacy notice is its own problem -- so it says so in the log instead.\n\n```go\nfunc IsEmbedded() bool\n```\nIsEmbedded reports whether the frontend is compiled into this binary.\n\n```go\nfunc NewSPAHandler(opts ...Option) http.Handler\n```\nNewSPAHandler returns an http.Handler that serves the embedded frontend. It resolves Next.js static-export dynamic routes (e.g. \\[id] -\u003e \\_) and falls back to index.html for client-side routing.\n\nWhen the frontend is not embedded (no embed\\_frontend build tag), the returned handler responds with 404 so the caller can fall back to a non-SPA welcome page.\n\n```go\nfunc NewSPAHandlerFS(fsys fs.FS, opts ...Option) http.Handler\n```\nNewSPAHandlerFS serves a static export from an arbitrary fs.FS, with the same route resolution NewSPAHandler applies to the embedded frontend.\n\nSite apps are served through this, from a zip bundle or from a directory rather than from embed.FS. That is what makes the path validation in serveFile load-bearing rather than belt-and-braces: embed.FS cannot reach anything outside the binary, and these filesystems can reach the real one.\n\n```go\nfunc PolicyURLOK(raw string) bool\n```\nPolicyURLOK reports whether a configured policy URL is one this UI will redirect to or put in an href: site-relative, or absolute http(s). Same rule, and the same reasons, as a configured logo.\n\n```go\nfunc RenderPolicyPage(p PolicyPage) ([]byte, error)\n```\nRenderPolicyPage renders one policy document as a standalone HTML page.\n\nStandalone, and not a route in the single-page app, for three reasons: the page has to render for a reader with no JavaScript (an OAuth2 provider's reviewer may be one, and so is a crawler); it has to work before anybody has signed in; and it is the one part of this UI whose exact text matters legally, which is an argument for the server emitting it directly from the configured bytes rather than through a client-side renderer.\n\n## Types\n\n```go\ntype Branding struct {\n\t// SiteName is the sidebar heading, SiteTagline the line beneath it,\n\t// and PageTitle the browser tab -- the two joined.\n\tSiteName    string `json:\"site_name\"`\n\tSiteTagline string `json:\"site_tagline\"`\n\tPageTitle   string `json:\"page_title\"`\n\t// FooterLogos is the institutional band at the foot of every page.\n\t// Nil is the band the UI ships with (CHTC, Morgridge, UW-Madison);\n\t// an empty list is no logos at all.\n\tFooterLogos []Logo `json:\"footer_logos\"`\n\t// SoftwareCredit asks the footer for its one-line \"Powered by\n\t// HTCondor\" credit, naming the Center for High Throughput Computing.\n\t// Set whenever the shipped logo band is not shown, so who wrote the\n\t// software is still said on every page -- and distinguished from who\n\t// runs the service, which is what the band above it says.\n\tSoftwareCredit bool `json:\"software_credit\"`\n\t// Favicon replaces the HTCondor mark in the browser tab.\n\tFavicon string `json:\"favicon,omitempty\"`\n\t// CustomCSS reports that this server serves a site stylesheet at\n\t// /branding.css, loaded after the page's own.\n\tCustomCSS bool `json:\"custom_css,omitempty\"`\n\t// PrivacyURL and TermsURL are where the footer links for the site's\n\t// policy pages point. Empty when the operator has configured none,\n\t// and the footer then says nothing about them -- see policy.go.\n\t//\n\t// Normally PrivacyPath and TermsPath, served by this server. A site\n\t// whose policy lives elsewhere (an institutional privacy notice,\n\t// say) gets that URL here instead, so the footer link shows a\n\t// reader where it is really going; the local path still redirects\n\t// there, for whoever was given it.\n\tPrivacyURL string `json:\"privacy_url,omitempty\"`\n\tTermsURL   string `json:\"terms_url,omitempty\"`\n\n\t// Rev changes whenever anything above does. It busts the injected\n\t// HTML cache and the stylesheet's URL after a reconfigure.\n\tRev uint64 `json:\"-\"`\n}\n```\nBranding is the resolved presentation of one deployment's web UI.\n\n```go\nfunc Build(o Options) (Branding, error)\n```\nBuild resolves configured values into a Branding.\n\nEvery part is independent, and a part that does not parse falls back to the shipped default rather than taking the rest of the branding down with it: a typo in the logo list should cost a site its logos, not its web UI. The error names every such fallback, for the caller to log.\n\n```go\nfunc DefaultBranding() Branding\n```\nDefaultBranding is the presentation of an unconfigured deployment.\n\n```go\nfunc (b Branding) Inject(page []byte) []byte\n```\nInject rewrites one exported HTML page to carry this branding.\n\nThree edits, all inside \\\u003chead\u003e: the title, the favicon link, and a trailing block with the branding as a JavaScript global plus the site stylesheet. The stylesheet goes last on purpose -- it is loaded after the app's own, which is what lets a site redefine the --color-brand-\\* variables and recolour the whole UI.\n\nA page with no \\\u003c/head\u003e is returned untouched; there is no such page in the export, and guessing where to put the block would be worse than leaving the site unbranded.\n\n```go\nfunc (b Branding) IsDefault() bool\n```\nIsDefault reports that nothing about this branding differs from what the frontend already hard-codes, so the server has nothing to say and serves the exported HTML byte for byte.\n\n```go\ntype Logo struct {\n\t// Src is the image URL: site-relative (\"/branding/af.svg\", normally\n\t// something out of HTTP_API_WEBUI_BRANDING_DIR) or absolute http(s).\n\tSrc string `json:\"src\"`\n\t// Alt is the text a screen reader reads and a broken image shows.\n\t// Required: an unlabelled institutional logo tells a blind user\n\t// nothing about who runs the service.\n\tAlt string `json:\"alt\"`\n\t// Href, when set, makes the logo a link.\n\tHref string `json:\"href,omitempty\"`\n}\n```\nLogo is one image in the footer's institutional band.\n\n```go\nfunc ParseLogos(raw string) ([]Logo, error)\n```\nParseLogos reads the configured footer band.\n\nReturns nil for an unset value -- the shipped band -- and a non-nil empty slice for \"\\[]\", which is a site saying it wants no logos.\n\n```go\ntype Option func(*spaHandler)\n```\nAn Option configures the SPA handler.\n\n```go\nfunc WithBranding(f func() Branding) Option\n```\nWithBranding gives the handler a source of site branding to splice into every HTML page it serves (see Branding.Inject). The function is called per request, so a reconfigure takes effect on the next page load; it may return the default branding, which injects nothing.\n\n```go\nfunc WithHeadHTML(html []byte) Option\n```\nWithHeadHTML splices a fixed block into the head of every HTML page this handler serves.\n\nUnlike branding, which an operator can change at runtime, this block is constant for the life of the handler: a site app is told its id and mount point, and those are properties of the bundle that was loaded. A reloaded bundle gets a new handler.\n\n```go\ntype Options struct {\n\tSiteName    string\n\tSiteTagline string\n\t// FooterLogos is a JSON array of {\"src\",\"alt\",\"href\"}. Empty keeps\n\t// the shipped band; \"[]\" removes it.\n\tFooterLogos string\n\tFavicon     string\n\t// CustomCSS reports that HTTP_API_WEBUI_CUSTOM_CSS names a readable\n\t// stylesheet. Resolving the path is the caller's job; this only\n\t// decides whether the page links to it.\n\tCustomCSS bool\n\t// PrivacyURL and TermsURL are where the footer's policy links\n\t// point, already resolved by the caller: empty for a site that has\n\t// configured no such page. Validated here all the same, since they\n\t// reach an href.\n\tPrivacyURL string\n\tTermsURL   string\n}\n```\nOptions are the raw configured values, as they come out of the configuration file.\n\n```go\ntype PolicyPage struct {\n\t// Title heads the page and names the browser tab, e.g. \"Privacy\n\t// Notice\". The document's own first heading is kept as well; this\n\t// is what the tab and the back-link say.\n\tTitle string\n\t// SiteName is the deployment's name, for the tab title and the\n\t// link back to the application.\n\tSiteName string\n\t// Markdown is the document, as configured.\n\tMarkdown []byte\n\t// CustomCSS links the site stylesheet, so a deployment that has\n\t// recoloured the UI gets a policy page that matches it.\n\tCustomCSS bool\n\t// Rev busts the stylesheet's cache, as elsewhere.\n\tRev uint64\n}\n```\nPolicyPage is one rendered policy document.\n\n","path":"github.com/htcondor/golang-htcondor/webapi/httpserver/webui","name":"webui","synopsis":"Package webui provides the embedded Next.js static export.","isRedistributable":true}
