Documentation
¶
Index ¶
- func FormatOutput(format OutputFormat, result *OutputResult) string
- func GetBaseURL(u string) string
- func GetDirFromURL(u string) string
- func IsAbsoluteURL(s string) bool
- func NormalizeURL(rawURL string) string
- func ResolveRelativePath(baseURL, relative string) string
- type AnalyzeInput
- type CacheDirs
- type ContentType
- type DiscoveredJS
- type InlineScript
- type Intermediate
- type JSMetadata
- type KnowledgeBase
- func (kb *KnowledgeBase) AddKnownPath(paths ...string)
- func (kb *KnowledgeBase) AddPrependURL(urls ...string)
- func (kb *KnowledgeBase) AddPublicPath(paths ...string)
- func (kb *KnowledgeBase) GetKnownPaths() []string
- func (kb *KnowledgeBase) GetPrependURLs() []string
- func (kb *KnowledgeBase) GetPublicPaths() []string
- func (kb *KnowledgeBase) IsSeenFragment(fragment string) bool
- func (kb *KnowledgeBase) IsSeenURL(url string) bool
- func (kb *KnowledgeBase) JSHasSourceMap(url string) bool
- func (kb *KnowledgeBase) MarkSeenFragment(fragment string)
- func (kb *KnowledgeBase) MarkSeenURL(url string)
- func (kb *KnowledgeBase) SetJSHasSourceMap(url string, has bool)
- type OutputFormat
- type OutputResult
- type Pipeline
- func (p *Pipeline) GetFoundCh() <-chan string
- func (p *Pipeline) GetKnowledge() *KnowledgeBase
- func (p *Pipeline) GetOutputResult() *OutputResult
- func (p *Pipeline) Run(ctx context.Context, startURL string) ([]string, error)
- func (p *Pipeline) SetBaseURL(url string)
- func (p *Pipeline) SetBrowserCookies(targetURL string, cookies []*http.Cookie) error
- func (p *Pipeline) SetCacheConfig(cfg *fetcher.CacheConfig)
- func (p *Pipeline) SetFetcherConfig(proxy, userAgent string)
- type Plugin
- type PluginRegistry
- type Result
- type SiteMetadata
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatOutput ¶
func FormatOutput(format OutputFormat, result *OutputResult) string
FormatOutput 格式化输出
func NormalizeURL ¶
NormalizeURL 规范化 URL,去除双斜杠、清理路径、清除 fragment
func ResolveRelativePath ¶
ResolveRelativePath 解析相对路径为绝对路径
Types ¶
type AnalyzeInput ¶
type AnalyzeInput struct {
SourceURL string // 当前内容来源 URL,绝对路径
ContentType ContentType // "html" | "js" | "json"
Content []byte // 资源内容
Headers http.Header // HTTP 响应头(用于 source map 等场景)
}
AnalyzeInput 插件分析的上下文输入
type CacheDirs ¶
type CacheDirs struct {
JS string `json:"js"`
SourceMap string `json:"sourceMap,omitempty"`
Source string `json:"source,omitempty"`
HTML string `json:"html,omitempty"`
}
CacheDirs 缓存目录
type ContentType ¶
type ContentType string
ContentType 类型安全常量
const ( ContentTypeHTML ContentType = "html" ContentTypeJS ContentType = "js" ContentTypeJSON ContentType = "json" )
type DiscoveredJS ¶
type DiscoveredJS struct {
// URL 发现的 JS URL
URL string
// FromURL 发现该 JS 的来源 URL(分析的是哪个 HTML/JS 文件)
FromURL string
// FromPlugin 发现该 JS 的插件名称
FromPlugin string
// IsInline 是否来自内联脚本
IsInline bool
}
DiscoveredJS 发现的 JS 详细信息
type InlineScript ¶
type InlineScript struct {
SourceURL string // 来源 HTML 的 URL
Index int // 脚本在 HTML 中的顺序索引
Content []byte // 脚本内容
}
InlineScript 行内脚本内容
type Intermediate ¶
type Intermediate struct {
URL string // 资源的绝对 URL
Type ContentType // 期望的资源类型
}
Intermediate 发现的中间配置资源
type JSMetadata ¶
type JSMetadata struct {
// URL 完整的 JS URL
URL string `json:"url"`
// LocalPath 本地文件路径
LocalPath string `json:"local_path"`
// SourceURL 发现该 JS 的来源 URL
SourceURL string `json:"source_url"`
// IsInline 是否来自内联脚本
IsInline bool `json:"is_inline"`
// SourceMapURL 关联的 source map URL(如果有)
SourceMapURL string `json:"source_map_url,omitempty"`
// SourceMapPath 本地 source map 文件路径(如果有)
SourceMapPath string `json:"source_map_path,omitempty"`
// FromPlugin 发现该 JS 的插件名称
FromPlugin string `json:"from_plugin,omitempty"`
// DiscoveredAt 发现时间(Unix timestamp)
DiscoveredAt int64 `json:"discovered_at"`
}
JSMetadata JS 文件的元数据信息
type KnowledgeBase ¶
type KnowledgeBase struct {
// PublicPaths 发现的 publicPath 列表
PublicPaths []string
// PrependURLs 用于拼接在文件名前面的 URL 列表
PrependURLs []string
// SeenURLs 已尝试过的 URL(无论成功/404)
SeenURLs map[string]bool
// SeenFragments 已探测过的 JS 路径片段
SeenFragments map[string]bool
// KnownPaths 已知存在的 JS 路径(用于优先拼接)
KnownPaths []string
// contains filtered or unexported fields
}
KnowledgeBase 全局知识库
func GetKnowledgeFromContext ¶
func GetKnowledgeFromContext(ctx context.Context) *KnowledgeBase
GetKnowledgeFromContext 从 context 中获取 KnowledgeBase
func (*KnowledgeBase) AddKnownPath ¶
func (kb *KnowledgeBase) AddKnownPath(paths ...string)
AddKnownPath 添加已知存在的 JS 路径
func (*KnowledgeBase) AddPrependURL ¶
func (kb *KnowledgeBase) AddPrependURL(urls ...string)
AddPrependURL 添加用于拼接的 URL
func (*KnowledgeBase) AddPublicPath ¶
func (kb *KnowledgeBase) AddPublicPath(paths ...string)
AddPublicPath 添加 publicPath
func (*KnowledgeBase) GetKnownPaths ¶
func (kb *KnowledgeBase) GetKnownPaths() []string
GetKnownPaths 获取所有已知路径
func (*KnowledgeBase) GetPrependURLs ¶
func (kb *KnowledgeBase) GetPrependURLs() []string
GetPrependURLs 获取所有用于拼接的 URL
func (*KnowledgeBase) GetPublicPaths ¶
func (kb *KnowledgeBase) GetPublicPaths() []string
GetPublicPaths 获取所有 publicPath
func (*KnowledgeBase) IsSeenFragment ¶
func (kb *KnowledgeBase) IsSeenFragment(fragment string) bool
IsSeenFragment 检查片段是否已探测
func (*KnowledgeBase) IsSeenURL ¶
func (kb *KnowledgeBase) IsSeenURL(url string) bool
IsSeenURL 检查 URL 是否已尝试
func (*KnowledgeBase) JSHasSourceMap ¶
func (kb *KnowledgeBase) JSHasSourceMap(url string) bool
JSHasSourceMap 检查 JS 是否有 source map
func (*KnowledgeBase) MarkSeenFragment ¶
func (kb *KnowledgeBase) MarkSeenFragment(fragment string)
MarkSeenFragment 标记片段已探测
func (*KnowledgeBase) MarkSeenURL ¶
func (kb *KnowledgeBase) MarkSeenURL(url string)
MarkSeenURL 标记 URL 已尝试
func (*KnowledgeBase) SetJSHasSourceMap ¶
func (kb *KnowledgeBase) SetJSHasSourceMap(url string, has bool)
SetJSHasSourceMap 标记 JS 是否有 source map
type OutputFormat ¶
type OutputFormat string
OutputFormat 输出格式
const ( FormatText OutputFormat = "text" FormatJSON OutputFormat = "json" FormatMD OutputFormat = "md" )
type OutputResult ¶
type OutputResult struct {
Summary Summary `json:"summary"`
JSURLs []string `json:"jsURLs"`
CacheBase string `json:"cacheBase,omitempty"`
CacheDirs *CacheDirs `json:"cacheDirs,omitempty"`
}
OutputResult 输出结果结构
type Pipeline ¶
type Pipeline struct {
// 调试模式
Debug bool
// contains filtered or unexported fields
}
Pipeline 主流程调度器
func (*Pipeline) GetFoundCh ¶
GetFoundCh 获取发现 JS URL 的 channel
func (*Pipeline) GetKnowledge ¶
func (p *Pipeline) GetKnowledge() *KnowledgeBase
GetKnowledge 获取知识库(用于测试)
func (*Pipeline) GetOutputResult ¶
func (p *Pipeline) GetOutputResult() *OutputResult
GetOutputResult 获取格式化输出结果
func (*Pipeline) SetBrowserCookies ¶ added in v0.3.0
SetBrowserCookies 注入浏览器 cookie 到 Fetcher
func (*Pipeline) SetCacheConfig ¶
func (p *Pipeline) SetCacheConfig(cfg *fetcher.CacheConfig)
SetCacheConfig 设置缓存配置
func (*Pipeline) SetFetcherConfig ¶
SetFetcherConfig 设置 Fetcher 配置(代理和 User-Agent)
type Plugin ¶
type Plugin interface {
// Name 插件的唯一标识名称
Name() string
// Precheck 快速过滤,返回 true 才执行 Analyze
Precheck(ctx context.Context, input *AnalyzeInput) bool
// Analyze 正式分析逻辑
Analyze(ctx context.Context, input *AnalyzeInput) (*Result, error)
}
Plugin 核心插件接口
type PluginRegistry ¶
type PluginRegistry struct {
// contains filtered or unexported fields
}
PluginRegistry 插件注册中心
type Result ¶
type Result struct {
// FromPlugin 来源插件名称
FromPlugin string
// URLs 明确且完整的 JS URL,直接加入下载队列
URLs []DiscoveredJS
// ProbeTargets 提取到的路径片段,待主流程探测
ProbeTargets []DiscoveredJS
// PublicPaths 发现的 publicPath 路径
PublicPaths []string
// PrependURLs 用于拼接在文件名前面的 URL(通常是 protocol-relative URL)
PrependURLs []string
// Intermediates 需要主流程去下载并重新分发的配置文件
Intermediates []Intermediate
// InlineScripts 行内脚本内容,需要主流程分析
InlineScripts []InlineScript
}
Result 插件分析的返回结果
type SiteMetadata ¶
type SiteMetadata struct {
// URLs 所有发现的 JS URL 信息
URLs []JSMetadata `json:"urls"`
// PrependURLs 探测时使用的 PrependURLs(拼接用的 CDN 前缀)
PrependURLs []string `json:"prepend_urls"`
// PublicPaths 探测时使用的 PublicPaths
PublicPaths []string `json:"public_paths"`
// DiscoveredAt 探测开始时间
DiscoveredAt int64 `json:"discovered_at"`
}
SiteMetadata 站点元数据(所有信息保存到一个 JSON 文件)