webpage

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webpage 渲染访客直接看到的独立页面:Web 服务的登录页、404/502 等错误页、管理后台的安全入口提示。

所有页面共用同一套布局与样式(浅色/深色自动切换);模板只描述结构,文案以中文字面量写在 Go 代码里, 渲染时按访客语言经 i18n 翻译后放进 .T,这样调整样式不需要改动各语言的译文。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(w http.ResponseWriter, r *http.Request, p Problem)

Error 输出错误页:浏览器得到样式化的 HTML 页面,其他客户端得到纯文本,与 http.Error 行为一致。

func Localize

func Localize(lang string, texts map[string]string) map[string]string

Localize 把以中文为键的文案表翻译成目标语言,返回新的表。

func MustRegister

func MustRegister(name, src string)

MustRegister 注册一个页面模板,src 需以 {{define "body"}} 定义主体;在包初始化时调用,模板错误直接 panic。

func Render

func Render(w http.ResponseWriter, status int, name, lang string, texts map[string]string, data map[string]any)

Render 以 status 状态码输出已注册的页面。data 会补上 Lang(访客语言)与 T(已翻译的 texts); PageTitle 为浏览器标签页标题,Host 非空时显示在页脚。

func WantsHTML

func WantsHTML(r *http.Request) bool

WantsHTML 判断请求方是否接受 HTML(浏览器导航请求)。

Types

type Problem

type Problem struct {
	Code   int
	Title  string // 标题,中文原文
	Detail string // 说明,中文原文
	Hint   string // 可选:额外的提示框内容,中文原文
	// Home 显示“返回首页”按钮;Retry 显示“重试”按钮(默认 5xx 显示)
	Home  bool
	Retry bool
	// Lock 用锁形图标(访问受限类提示),默认按状态码选择图标
	Lock bool
	// Action 非空时显示一个主按钮,跳转到该站内地址;ActionText 为按钮文字(中文原文)
	Action     string
	ActionText string
}

Problem 描述一个错误页。

Jump to

Keyboard shortcuts

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