route

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Favicon

func Favicon(w http.ResponseWriter)

func FileDownload

func FileDownload(w http.ResponseWriter, r *http.Request, path string)

FileDownload 下载文件

func FilePlay

func FilePlay(w http.ResponseWriter, r *http.Request, path string)

FilePlay 播放文件

func RenderErrorText

func RenderErrorText(w http.ResponseWriter, resp *ErrorResp)

Types

type Config

type Config struct {
	Root  string `json:"root" yaml:"root"`   // 文件根目录
	Index string `json:"index" yaml:"index"` // 默认首页

	// 静态文件的请求地址加了一个前缀,比如/html的时候,
	// 就可以通过这个参数来去掉请求 path部分中的前面这部分内容。
	// 用最后部分去匹配文件系统。
	URLPrefix string `json:"url_prefix" yaml:"url_prefix"` // 路由前缀
}

type EmbedInfo

type EmbedInfo struct {
	Search string // 用search 去匹配请求path的前面部分,看是否包含 string.HasPrefix(path,search)

	// 这是缓存系统的前缀
	// 当缓存系统设置的路径是 html/static/xxx的时候
	// 实际请求路径是 static/xxx
	// 这个情况下实际路径不包含html,如果直接用search匹配,就会失败,可以通过这个prefix前缀补充,再去匹配。
	Prefix string
	FS     *embed.FS // 内置embed fs 系统
}

type ErrorResp

type ErrorResp struct {
	Code  int
	Msg   string
	Error error
}

func HttpFS

func HttpFS(hfs http.FileSystem, path string) (http.File, fs.FileInfo, *ErrorResp)

HttpFS 获取文件

type Route

type Route struct {
	// contains filtered or unexported fields
}

func New

func New(opt *Config) *Route

func (*Route) AddEmbed

func (ro *Route) AddEmbed(e *EmbedInfo)

AddEmbed 添加静态文件系统

func (*Route) Index

func (ro *Route) Index(w http.ResponseWriter, r *http.Request)

type RouteType

type RouteType string

noinspection all

const (
	Static   RouteType = "static"   // 静态路由
	Param    RouteType = "param"    // 路径参数路由(如 /users/:id)
	Regex    RouteType = "regex"    // 正则表达式路由
	Wildcard RouteType = "wildcard" // 通配符路由
)

noinspection all

func (RouteType) GormDBDataType

func (RouteType) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type noinspection all

func (*RouteType) Scan

func (r *RouteType) Scan(val any) (err error)

noinspection all

func (RouteType) Value

func (r RouteType) Value() (driver.Value, error)

noinspection all

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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