tools

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminApiPrefix

func AdminApiPrefix() string

AdminApiPrefix 返回后台 API 前缀,不含前导和结尾斜杠。

func AdminAssetsPath

func AdminAssetsPath() string

AdminAssetsPath 返回后台静态资源挂载路径,以 / 开头且不含结尾斜杠。

func AdminLang

func AdminLang(ctx http.Context, key string) string

func AdminPagePath

func AdminPagePath() string

AdminPagePath 返回后台页面挂载路径,以 / 开头且不含结尾斜杠。

func AppUrl

func AppUrl() string

AppUrl 返回不带结尾斜杠的 APP_URL,未配置时为空字符串。

func AuthGuard

func AuthGuard() string

AuthGuard 返回后台使用的 auth guard 名称,默认 admin。

登录、注销与中间件校验必须统一走这个 guard,否则签发的 token 会落到宿主的默认 guard 上,导致带 token 的请求被判为未认证。

func GetAdmin

func GetAdmin(str string) string

func GetAdminNil

func GetAdminNil() string

func GetApi

func GetApi(str string) string

func GetApiNil

func GetApiNil() string

func GetFileUrl

func GetFileUrl() string

GetFileUrl 上传文件地址

func GetImageUrl

func GetImageUrl() string

GetImageUrl 上传图片地址

func KebabToCamel

func KebabToCamel(str string) string

KebabToCamel 中划线转小驼峰

func Map2options

func Map2options(m map[string]string) []map[string]string

map2options takes a map[string]string and returns a slice of maps with "label" and "value" keys.

func MatchPath added in v1.17.1

func MatchPath(pattern, requestPath string) bool

MatchPath 判断 requestPath 是否命中 pattern。

pattern 支持尾部通配符(如 "/admin-api/system/*")。两侧都会保留前导斜杠, 因为 ctx.Request().Path() 返回的是 "/admin-api/..." 这种完整路径; 之前调用方把 pattern 的前导斜杠 trim 掉了,导致通配符永不命中。

func PascalToCamel

func PascalToCamel(s string) string

PascalToCamel 大驼峰转小驼峰

func PascalToSnake

func PascalToSnake(s string) string

PascalToSnake 大驼峰转蛇形

func ReadDir

func ReadDir(dir string) []string

ReadDir 读取目录下的所有文件, 返回文件名列表

func RequestIs

func RequestIs(ctx http.Context, path string) bool

RequestIs 判断请求是否是指定的路径

func RequestMethodIs

func RequestMethodIs(ctx http.Context, method string) bool

* * RequestMethodIs 判断请求是否是指定的方法

func SnakeToPascal

func SnakeToPascal(s string) string

SnakeToPascal 蛇形转大驼峰

func Url

func Url(str string) string

func UrlNil

func UrlNil() string

func VerifyExport

func VerifyExport(path string, expires string, signature string) error

VerifyExport 校验下载请求的签名与有效期。

Types

type ExportFile

type ExportFile struct {
	Path      string `json:"path"`
	Expires   string `json:"expires"`
	Signature string `json:"signature"`
}

ExportFile 描述一次导出的结果。

前端拿到这三个字段后会直接拼出下载地址,后端在下载时重新校验签名, 避免任意路径读取。

func BuildExport

func BuildExport(disk string, sheetName string, headers []string, rows [][]any) (*ExportFile, error)

BuildExport 把表头与数据行渲染成 xlsx 并返回签名后的下载信息。

Jump to

Keyboard shortcuts

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