Documentation
¶
Overview ¶
Package server 组装 HTTP 路由与服务生命周期。
Index ¶
Constants ¶
View Source
const ( PrefixConsole = api.PrefixConsole PrefixPublic = api.PrefixPublic PrefixExtension = api.PrefixExtension )
三平面路由前缀,定义在 api 包,这里保留别名便于引用与测试。
View Source
const UploadsPath = "/uploads"
UploadsPath 是本地存储附件的对外访问前缀。
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Authenticator ¶
type Authenticator interface {
// Middleware 解析凭据并注入 context,但不强制要求已认证。
Middleware(next http.Handler) http.Handler
// CSRF 校验非安全方法的 CSRF 令牌。
CSRF(next http.Handler) http.Handler
}
Authenticator 是路由层所需的鉴权能力。
定义在使用方(消费者侧接口,Go 惯例),使 server 不依赖 auth 的具体实现, 也让接线测试可以替换成轻量替身而不必连数据库。
type Options ¶
type Options struct {
Logger *slog.Logger
// Authenticator 为 nil 时不挂载鉴权中间件,仅用于测试路由骨架。
Authenticator Authenticator
// ClientIP 为 nil 时不解析转发头,一律使用直连地址。
ClientIP *httpx.ClientIPResolver
// Version 写入 OpenAPI 文档的 info.version。
Version string
// MaxBodySize 是普通请求体的字节上限,0 表示用默认值。
MaxBodySize int64
// MaxUploadSize 是 multipart 请求体的字节上限,0 表示用默认值。
MaxUploadSize int64
// UploadsDir 非空时把该目录以静态文件形式挂在 /uploads 下,供本地存储的附件访问。
UploadsDir string
// FallbackRootToConsole 为真时把根路径重定向到 Console。
//
// 仅供没有装配主题模块的场景(路由骨架测试、未来的纯 API 模式)使用:
// 正常运行时根路径是访客前台,由 theme 模块接管。
FallbackRootToConsole bool
// InstallRedirect 非空时(首次安装向导模式)把站点入口重定向到该地址。
//
// 站长此时打开浏览器应当看到安装向导,而不是一个登不进去的登录页。
// 拦的只是入口,/console/assets/* 照常提供 —— 向导自己也跑在这个 SPA 里。
InstallRedirect string
}
Options 是构造路由所需的依赖。
Click to show internal directories.
Click to hide internal directories.