Documentation
¶
Index ¶
- Variables
- func CanAccess(user *model.User, meta *model.Meta, reqPath string, password string) bool
- func CanWrite(meta *model.Meta, path string) bool
- func ContentWithValue(ctx context.Context, keyAndValue ...any) context.Context
- func ErrorResp(c *gin.Context, err error, code int, l ...bool)
- func ErrorStrResp(c *gin.Context, str string, code int, l ...bool)
- func ErrorWithDataResp(c *gin.Context, err error, code int, data any, l ...bool)
- func GenerateToken(user *model.User) (tokenString string, err error)
- func GetApiUrl(ctx context.Context) string
- func GetApiUrlFromRequest(r *http.Request) string
- func GetEtag(file model.Obj) string
- func GinWithValue(c *gin.Context, keyAndValue ...any)
- func InvalidateToken(tokenString string) error
- func IsApply(metaPath, reqPath string, applySub bool) bool
- func IsStorageSignEnabled(rawPath string) bool
- func IsTokenInvalidated(tokenString string) bool
- func Pluralize(count int, singular, plural string) string
- func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.Obj) error
- func ProxyRange(ctx context.Context, link *model.Link, size int64)
- func ShouldProxy(storage driver.Driver, filename string) bool
- func Sign(obj model.Obj, parent string, encrypt bool) string
- func SuccessResp(c *gin.Context, data ...any)
- func SuccessWithMsgResp(c *gin.Context, msg string, data ...any)
- type InterceptResponseWriter
- type PageResp
- type Resp
- type UserClaims
- type WrittenResponseWriter
Constants ¶
This section is empty.
Variables ¶
var SecretKey []byte
SecretKey 用于JWT签名的密钥
Functions ¶
func CanAccess ¶
CanAccess 检查用户是否可以访问指定路径
参数:
- user: 用户对象
- meta: 元数据对象
- reqPath: 请求路径
- password: 访问密码
返回:
- bool: 如果用户可以访问返回true,否则返回false
func CanWrite ¶
CanWrite 检查指定元数据和路径是否具有写入权限
参数:
- meta: 元数据对象
- path: 请求路径
返回:
- bool: 如果有写入权限返回true,否则返回false
func ContentWithValue ¶ added in v4.2.3
func ErrorResp ¶
ErrorResp 返回错误响应 封装了ErrorWithDataResp函数,不包含额外数据
参数:
- c: Gin上下文
- err: 错误信息
- code: 错误码
- l: 可选参数,是否记录日志,默认为不记录
func ErrorStrResp ¶
ErrorStrResp 返回字符串错误响应 与ErrorResp类似,但接受字符串而非error类型
参数:
- c: Gin上下文
- str: 错误消息字符串
- code: 错误码
- l: 可选参数,是否记录日志,默认为不记录
func ErrorWithDataResp ¶
ErrorWithDataResp 返回带数据的错误响应 如果指定记录日志,会根据调试模式决定日志详细程度
参数:
- c: Gin上下文
- err: 错误信息
- code: 错误码
- data: 额外数据
- l: 可选参数,是否记录日志,默认为不记录
func GetApiUrlFromRequest ¶ added in v4.2.3
GetApiUrlFromRequest 根据请求信息生成API的完整URL 如果配置中的SiteURL已经是完整URL,则直接使用 否则根据请求信息构建完整URL 参数:
- r: HTTP请求,可以为nil
返回:
- 完整的API URL,不带尾部斜杠
func GinWithValue ¶ added in v4.2.3
func IsApply ¶
IsApply 检查元数据是否应用于请求路径
参数:
- metaPath: 元数据路径
- reqPath: 请求路径
- applySub: 是否应用于子路径
返回:
- bool: 如果元数据应用于请求路径返回true,否则返回false
func IsStorageSignEnabled ¶
IsStorageSignEnabled 检查指定路径的存储是否启用了签名
参数:
- rawPath: 原始路径
返回:
- bool: 如果存储启用了签名返回true,否则返回false
func IsTokenInvalidated ¶
IsTokenInvalidated 检查令牌是否已被注销
参数:
- tokenString: 令牌字符串
返回:
- bool: 如果令牌已被注销返回true,否则返回false
func Pluralize ¶
Pluralize 根据数量返回单数或复数形式的字符串
参数:
- count: 数量
- singular: 单数形式
- plural: 复数形式
返回:
- 根据count选择的字符串
func Proxy ¶
Proxy 处理文件代理请求 根据link中的不同信息,采用不同的代理方式: 1. 使用MFile直接提供文件 2. 使用RangeReadCloser处理范围请求 3. 使用分块下载处理大文件 4. 使用透明代理转发请求
参数:
- w: HTTP响应写入器
- r: HTTP请求
- link: 链接信息
- file: 文件对象
返回:
- error: 错误信息
func ProxyRange ¶
ProxyRange 为链接设置范围读取器 如果链接已经有MFile,则不需要设置 如果链接的RangeReadCloser为NoProxyRange,则设置为nil
参数:
- link: 链接对象
- size: 文件大小
func ShouldProxy ¶
ShouldProxy 判断是否应该代理指定的文件 代理条件: 1. 存储配置必须代理 2. 存储启用了Web代理 3. 文件扩展名在代理类型列表中
参数:
- storage: 存储驱动
- filename: 文件名
返回:
- bool: 如果应该代理返回true,否则返回false
func Sign ¶
Sign 为对象生成签名 目录对象不生成签名 非加密对象,在未开启全局签名的情况下不生成签名
参数:
- obj: 需要签名的对象
- parent: 父路径
- encrypt: 是否是加密对象
返回:
- 签名字符串,如果不需要签名则返回空字符串
Types ¶
type InterceptResponseWriter ¶
type InterceptResponseWriter struct {
http.ResponseWriter
io.Writer
}
InterceptResponseWriter 拦截响应写入的ResponseWriter 允许将响应内容写入到指定的Writer
type Resp ¶
type Resp[T any] struct { Code int `json:"code"` // 状态码,200表示成功 Message string `json:"message"` // 响应消息 Data T `json:"data"` // 响应数据 }
Resp 通用响应结构体,用于API返回数据 使用泛型支持不同类型的数据 参数:
- T: 数据类型参数,可以是任意类型
type UserClaims ¶
type UserClaims struct {
Username string `json:"username"` // 用户名
PwdTS int64 `json:"pwd_ts"` // 密码时间戳(用于在密码更改时使token失效)
jwt.RegisteredClaims
}
UserClaims JWT中包含的用户信息
func ParseToken ¶
func ParseToken(tokenString string) (*UserClaims, error)
ParseToken 解析JWT令牌
参数:
- tokenString: 令牌字符串
返回:
- *UserClaims: 解析出的用户声明
- error: 错误信息
type WrittenResponseWriter ¶
type WrittenResponseWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
WrittenResponseWriter 跟踪是否已经写入内容的ResponseWriter
func (*WrittenResponseWriter) IsWritten ¶
func (ww *WrittenResponseWriter) IsWritten() bool
IsWritten 检查是否已经写入内容
返回:
- bool: 如果已经写入内容返回true,否则返回false