app

package
v0.0.0-...-f9bc9d0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: GPL-3.0 Imports: 50 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package app 应用程序主入口,app\app.go

Package app: errors.go — 应用级别可传播错误哨兵值

app/log.go

Package app: server.go,内核库

Package app: share_utils.go

Index

Constants

View Source
const (
	DefaultPort     = ":8199"
	LogTimeFormat   = "2006-01-02 15:04:05"
	MaxLogLines     = 100
	ShareDirName    = "more"
	TemplatePattern = "templates/*.html"
	StaticPrefix    = "/static"
	AdminPath       = "/admin"
	SubPath         = "/sub"
	SharePath       = "/share"
	PublicPath      = "/more"
	FilesPath       = "/files"
	AnalysisPath    = "/analysis"
	SubInfoPath     = substore.SubInfoPath
	APIAuthHeader   = "X-API-Key"
	HeaderFromCheck = "X-From-Subs-Check-pro"
	QueryFromCheck  = "from_subs_check_pro"
)

Variables

View Source
var ErrFirstRun = errors.New("first-run: config.yaml already created, please edit and restart")

ErrFirstRun 首次运行错误哨兵值。

当 config.yaml 不存在时,Initialize() 会创建默认配置文件并返回此错误。 调用方(CLI / GUI)应根据自身模式做不同处理:

  • CLI: 打印提示信息后 os.Exit(0)
  • GUI: 设置环境变量通知前端登录窗口展示引导提示,不退出进程

由于 Initialize() 内部用 fmt.Errorf("%w", ...) 包装, 调用方需使用 errors.Is(err, app.ErrFirstRun) 判断。

Functions

func AnalysisReportPath

func AnalysisReportPath() (string, error)

AnalysisReportPath 返回分析报告路径

func GetCanonicalBaseURL

func GetCanonicalBaseURL(c *gin.Context) string

GetCanonicalBaseURL 计算当前请求的权威基准 URL(优先 public-url,次之 X-Forwarded 反代头,兜底 Host)

func GetLogLevel

func GetLogLevel() slog.Level

GetLogLevel 获取配置的日志级别

func GetLogPath

func GetLogPath() (string, error)

GetLogPath 获取日志路径

func InitLoggerFile

func InitLoggerFile() (slog.Handler, error)

InitLoggerFile 初始化纯文件日志系统 供 GUI 在 main() 环境就绪后调用,也供 CLI 在 init() 中作为基础组件调用 返回 fileHandler 以便 CLI 模式继续组合终端输出

func MaskIP

func MaskIP(ip string) string

MaskIP 对 IP 末段打码(展示用):1.2.3.4 → 1.2.3.*;IPv6 截断。

func ReadLastNLines

func ReadLastNLines(filePath string, n int) ([]string, error)

ReadLastNLines 读取最新日志

func RegisterGroupRoutes

func RegisterGroupRoutes(router *gin.Engine, outputPath string, authMiddleware gin.HandlerFunc)

RegisterGroupRoutes 注册按组分发的订阅端点 /group/:name/*

func RegisterSubStoreProxy

func RegisterSubStoreProxy(router *gin.Engine, targetURL string, authMiddleware gin.HandlerFunc) error

RegisterSubStoreProxy 将 /sub-store/* 内部反向代理至 127.0.0.1:8299

func UnifiedAuthMiddleware

func UnifiedAuthMiddleware(expectedKey string) gin.HandlerFunc

UnifiedAuthMiddleware 提供全站统一鉴权中间件 优先级支持: 1. URL Query 参数: ?token=xxx 或 ?api_key=xxx 2. HTTP Header: X-API-Key: xxx 3. HTTP Header: Authorization: Bearer xxx

【安全修复 2026-11-10】该函数改为运行时每次请求动态读取 config.GlobalConfig.APIKey, 杜绝「中间件闭包捕获初始 key、配置热重载后旧 key 永久有效」的凭据轮换失效问题(CRITICAL)。

Types

type App

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

App 结构体用于管理应用程序状态

func New

func New(originVersion string, version string, configPath string) *App

New 创建新的应用实例 不再在这里调用 flag.Parse() 或定义 flags,全部由 main 负责。

func (*App) CheckPortConflict

func (app *App) CheckPortConflict() (httpPortAvailable bool, subStorePortAvailable bool)

CheckPortConflict 检查HTTP和sub-store端口冲突

需先初始化配置加载

err := app.InitConfigLoad()

func (*App) CheckUpdateAndRestart

func (app *App) CheckUpdateAndRestart(silentUpdate bool)

CheckUpdateAndRestart 检查并自动更新

func (*App) GetConfigPath

func (app *App) GetConfigPath() string

GetConfigPath 返回 Initialize() 确定后的配置文件绝对路径。 在 Initialize() 调用前返回空字符串。

func (*App) GetCurrentState

func (app *App) GetCurrentState() StatusData

GetCurrentState 提取状态逻辑,供 API 和 GUI 共同调用

func (*App) GetLastCheckResult

func (app *App) GetLastCheckResult() string

GetLastCheckResult 返回最后一次检测的结果(格式化好的单行字符串) 供 GUI 直接在菜单栏展示

func (*App) GetRouter

func (app *App) GetRouter() *gin.Engine

GetRouter 供 Wails GUI 复用同一路由

func (*App) InitConfigLoad

func (app *App) InitConfigLoad() error

InitConfigLoad 初始化配置文件加载

func (*App) InitUpdateInfo

func (app *App) InitUpdateInfo()

InitUpdateInfo 检查是否为重启进程

func (*App) Initialize

func (app *App) Initialize() error

Initialize 初始化应用程序

func (*App) IsChecking

func (app *App) IsChecking() bool

IsChecking 返回当前是否正在执行检测任务

func (*App) Run

func (app *App) Run()

Run 运行应用程序主循环

func (*App) SetPorts

func (app *App) SetPorts(httpPort, subStorePort string) error

SetPorts 更新端口配置。

func (*App) SetupUpdateTasks

func (app *App) SetupUpdateTasks()

SetupUpdateTasks 初始化并启动所有后台更新任务(仅在程序启动时调用一次)

func (*App) Shutdown

func (app *App) Shutdown() error

Shutdown 尝试优雅关闭所有子服务与资源

func (*App) TriggerCheck

func (app *App) TriggerCheck()

TriggerCheck 供外部调用的触发检测方法

func (*App) UpdateGeoDBCron

func (app *App) UpdateGeoDBCron()

UpdateGeoDBCron 独立配置 GeoLite2 数据库更新任务

func (*App) UpdateSelfUpdateCron

func (app *App) UpdateSelfUpdateCron()

UpdateSelfUpdateCron 独立配置/更新主程序定时检测升级任务

func (*App) UpdateSubStoreCron

func (app *App) UpdateSubStoreCron()

UpdateSubStoreCron 独立配置 Sub-Store 更新任务

type FileEntry

type FileEntry struct {
	Name    string
	Size    string
	ModTime string
}

FileEntry 表示目录中的单个文件条目

type IPHit

type IPHit struct {
	IP   string    `json:"ip"`
	Time time.Time `json:"time"`
	File string    `json:"file"`
	UA   string    `json:"ua"`
}

IPHit 单次拉取记录(IP 脱敏后展示)。

type Share

type Share struct {
	ID        string    `json:"id"`
	GroupName string    `json:"group"`
	Enabled   bool      `json:"enabled"`
	Note      string    `json:"note"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"` // 零值 = 永不过期
	Files     []string  `json:"files"`      // 空 = 全部文件
}

Share 是一个按组分发项,独立于组配置存在(可增删/开关)。 分享码即 URL 中的 code,12 字符 base62,不可枚举。

type SharePageData

type SharePageData struct {
	Title       string
	HeaderColor string
	HeaderIcon  template.HTML // 允许内联 SVG,不转义
	HeaderTitle string
	Description template.HTML // 允许 <code> 等标签
	ExtraHint   template.HTML
	FooterText  string
	ShowInput   bool
	BadgeStyle  string // "success" | "warning" | "danger" | "idle"
	BadgeText   string
	Files       []FileEntry
	ShareCode   string
}

SharePageData 定义渲染 share.html 所需的全部数据

type ShareStats

type ShareStats struct {
	ShareID   string         `json:"share_id"`
	TotalHits int            `json:"total_hits"`
	UniqueIPs int            `json:"unique_ips"`
	LastHit   time.Time      `json:"last_hit"`
	PerFile   map[string]int `json:"per_file"`
	IPHistory []IPHit        `json:"ip_history"` // 环形,上限 maxIPHistory
	// contains filtered or unexported fields
}

ShareStats 分享项的拉取统计。

type ShareStore

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

ShareStore 管理分享项与统计的内存态 + 落盘。

func GetShareStore

func GetShareStore() *ShareStore

GetShareStore 返回全局分享存储(懒加载)。

func NewShareStore

func NewShareStore() *ShareStore

NewShareStore 创建并加载分享存储。

func (*ShareStore) Create

func (s *ShareStore) Create(group, note string, expiresAt time.Time, files []string) (*Share, error)

Create 创建新分享;group 必须非空;返回生成的分享(含随机码)。

func (*ShareStore) Delete

func (s *ShareStore) Delete(id string) bool

Delete 删除分享项(统计数据保留在 stats 中并标记 deleted 由调用方处理)。

func (*ShareStore) Flush

func (s *ShareStore) Flush()

Flush 强制把内存态落盘(定时器/退出时调用)。

func (*ShareStore) Get

func (s *ShareStore) Get(id string) (*Share, bool)

Get 按 id 取分享项。

func (*ShareStore) GetStats

func (s *ShareStore) GetStats(shareID string) (*ShareStats, bool)

GetStats 取某分享的统计。

func (*ShareStore) List

func (s *ShareStore) List() []*Share

List 返回全部分享项(按创建时间倒序)。

func (*ShareStore) ListStats

func (s *ShareStore) ListStats() map[string]*ShareStats

ListStats 取全部统计(用于管理页)。

func (*ShareStore) RecordHit

func (s *ShareStore) RecordHit(shareID, ip, file, ua string)

RecordHit 记录一次拉取(内存累加,落盘由 Flush 或定时器触发)。

func (*ShareStore) Toggle

func (s *ShareStore) Toggle(id string, enabled bool) bool

Toggle 开关分享。

type StatusData

type StatusData struct {
	IsChecking     bool
	StepName       string
	ProxyCount     int64
	Processed      int64
	Available      int64
	Progress       int64
	ETASuffix      string
	LastCheckTime  string
	LastTotal      int64
	LastAvailable  int64
	ProcessResults bool
}

StatusData 包含当前检测的所有状态信息

Directories

Path Synopsis
Package monitor 内存监控
Package monitor 内存监控

Jump to

Keyboard shortcuts

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