Documentation
¶
Overview ¶
Package static provides static file and SPA helpers. Package static 提供静态文件与 SPA 辅助函数。
Index ¶
- Variables
- func Mount(router chi.Router, prefix string, relPath string, opts Options) error
- func MountSPA(router chi.Router, prefix string, relPath string, opts Options) (http.Handler, error)
- func ResolveDir(relPath string, opts Options) (string, error)
- func ResolveSPADir(relPath string, opts Options) (string, error)
- func SPAHandler(relPath string, opts Options) (http.Handler, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidProjectPath = errors.New("static: invalid project path")
Functions ¶
func Mount ¶
Mount mounts a file server at prefix. Call Mount(router, prefix, relPath, opts). Mount 在 prefix 挂载文件服务器。 调用 Mount(router, prefix, relPath, opts)。
func MountSPA ¶
MountSPA mounts a SPA handler at prefix. Call MountSPA(router, prefix, relPath, opts). MountSPA 在 prefix 挂载 SPA handler。 调用 MountSPA(router, prefix, relPath, opts)。
func ResolveDir ¶
ResolveDir returns the directory for relPath. relPath must be project-relative. ResolveDir 返回 relPath 对应目录。 relPath 必须是项目相对路径。
func ResolveSPADir ¶
ResolveSPADir returns the SPA directory for relPath. index.html must exist. ResolveSPADir 返回 relPath 对应的 SPA 目录。 必须存在 index.html。
func SPAHandler ¶
SPAHandler returns a handler with SPA history fallback. relPath must be project-relative, for example "dist" or "web/dist". Call handler, err := SPAHandler(relPath, opts). Inject through routes.HandlerOptions.NotFound for application fallback. SPAHandler 返回带 SPA history 回退的 handler。 relPath 必须是项目相对路径,例如 "dist" 或 "web/dist"。 调用 handler, err := SPAHandler(relPath, opts)。 通过 routes.HandlerOptions.NotFound 注入应用兜底。