transfer

package
v0.33.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package transfer 提供传输日志(上传/下载)的异步记录。

背景:TransferLog 模型/DAO/前端页面早已存在,但全库无任何写入方, 传输日志页与趋势统计的下载序列一直是空数据——本包是写入侧的唯一收口。 记录失败只记运行日志,绝不影响主流程。

落盘能力经 Sink 注入(bootstrap 以 dao 仓储桥接):pkg 是最底层共享库, 不直接依赖 repo 层。

Index

Constants

View Source
const (
	OpUpload   = "upload"
	OpDownload = "download"
)

操作类型常量(与 model.TransferLog.Operation 语义一致)

Variables

This section is empty.

Functions

func Flush

func Flush(d time.Duration)

Flush 等待在飞日志落盘,至多等待 d。优雅停机与测试清理用—— 异步 goroutine 持有 DB/文件句柄写盘,调用方(如测试的 TempDir 清理) 必须先排水再释放底层资源,否则出现"readonly database/目录非空"竞争。

func Record

func Record(e Entry)

Record 异步记录一次传输(GoSafe 兜底 panic,不影响主流程)。

func SetSink

func SetSink(s Sink)

SetSink 注入落盘实现(bootstrap 装配调用;须先于任何服务流量)。

Types

type Entry

type Entry struct {
	Operation  string // upload | download
	FileCodeID uint
	Code       string
	FileName   string
	FileSize   int64
	UserID     *uint
	APIKeyID   *uint // 非 nil 表示该操作经用户级 API Key 认证(泄露排查归因用)
	Username   string
	IP         string
	DurationMs int64
}

Entry 一次传输的归因信息。UserID/APIKeyID 为 nil 表示匿名/JWT 认证。

type Sink

type Sink interface {
	Create(ctx context.Context, e Entry) error
}

Sink 传输日志落盘能力(repo/db/dao 的仓储实现,bootstrap 装配注入)。

Jump to

Keyboard shortcuts

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