Documentation
¶
Overview ¶
Package static provides static file serving and SPA mounting. 静态文件服务和 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. relPath must be a project-relative location. Mount 在 prefix 挂载文件服务器;relPath 必须是项目内相对位置。
func MountSPA ¶
func MountSPA(router chi.Router, prefix string, relPath string, opts ...Options) (http.Handler, error)
MountSPA mounts a SPA handler at prefix. relPath must be a project-relative location. MountSPA 在 prefix 挂载 SPA 处理器;relPath 必须是项目内相对位置。
func ResolveDir ¶
ResolveDir locates a static directory by project-relative path. ResolveDir 通过项目内相对路径定位静态目录。
func ResolveSPADir ¶
ResolveSPADir locates a SPA directory and requires index.html. ResolveSPADir 定位 SPA 目录,并要求存在 index.html。
func SPAHandler ¶
SPAHandler returns a SPA handler with history API fallback. relPath must be a project-relative location such as "dist" or "web/dist". SPAHandler 返回支持 history API 回退的 SPA 处理器; relPath 必须是项目内相对位置,例如 "dist" 或 "web/dist"。 Example / 示例:
handler, _ := static.SPAHandler("dist")
r.Handle("/*", handler)