static

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package static provides static file serving and SPA mounting. 静态文件服务和 SPA 挂载。

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidProjectPath = errors.New("static: invalid project path")

Functions

func Mount

func Mount(router chi.Router, prefix string, relPath string, opts ...Options) error

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

func ResolveDir(relPath string, opts ...Options) (string, error)

ResolveDir locates a static directory by project-relative path. ResolveDir 通过项目内相对路径定位静态目录。

func ResolveSPADir

func ResolveSPADir(relPath string, opts ...Options) (string, error)

ResolveSPADir locates a SPA directory and requires index.html. ResolveSPADir 定位 SPA 目录,并要求存在 index.html。

func SPAHandler

func SPAHandler(relPath string, opts ...Options) (http.Handler, error)

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)

Types

type Options

type Options struct {
	AppDir appdir.Options
}

Options configures static asset discovery. Options 配置静态资源发现。

Jump to

Keyboard shortcuts

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