Documentation
¶
Overview ¶
Package validator 提供 OFD 文件结构、资源、XML 和签名的校验能力。
Index ¶
- Constants
- func RenderJSON(w io.Writer, report Report, pretty bool) error
- func RenderMarkdown(w io.Writer, report Report) error
- func RenderPDF(w io.Writer, report Report, options PDFOptions) error
- func RenderText(w io.Writer, report Report) error
- type CheckResult
- type InputInfo
- type Issue
- type Mode
- type Option
- func WithCheckDigest(value bool) Option
- func WithFailOnWarning(value bool) Option
- func WithMaxEntries(value int) Option
- func WithMaxErrors(value int) Option
- func WithMaxFileSize(value int64) Option
- func WithMaxInputSize(value int64) Option
- func WithMaxTotalSize(value int64) Option
- func WithMaxXMLBytes(value int64) Option
- func WithMaxXMLDepth(value int) Option
- func WithMaxXMLNodes(value int) Option
- func WithMode(value Mode) Option
- func WithScanXML(value bool) Option
- func WithSchemas(value *schema.Set) Option
- func WithSkipXSD(value bool) Option
- type Options
- type PDFOptions
- type Report
- type Severity
- type Stage
- type Status
- type Summary
- type ToolInfo
- type Validator
Constants ¶
View Source
const ToolVersion = "0.1.0"
ToolVersion 是校验器报告中的工具版本。
Variables ¶
This section is empty.
Functions ¶
func RenderJSON ¶
RenderJSON 将报告编码为 JSON;英文枚举用于机器处理,*_zh 字段提供中文标签。
func RenderMarkdown ¶
RenderMarkdown 将报告输出为中文 Markdown。
Types ¶
type CheckResult ¶
type CheckResult struct {
// Name 是校验阶段的英文名称。
Name string `json:"name"`
// NameZh 是校验阶段的中文名称。
NameZh string `json:"name_zh,omitempty"`
// Status 是校验阶段的英文状态。
Status string `json:"status"`
// StatusZh 是校验阶段的中文状态。
StatusZh string `json:"status_zh,omitempty"`
}
CheckResult 描述一个校验阶段的结果。
type InputInfo ¶
type InputInfo struct {
// Path 是被校验的输入文件路径或名称。
Path string `json:"path"`
// Size 是输入数据的字节数。
Size int64 `json:"size"`
}
InputInfo 描述被校验的输入文件。
type Issue ¶
type Issue struct {
// Severity 是问题的英文严重程度。
Severity Severity `json:"severity"`
// SeverityZh 是问题严重程度的中文名称。
SeverityZh string `json:"severity_zh,omitempty"`
// Stage 是问题所属校验阶段的英文名称。
Stage Stage `json:"stage"`
// StageZh 是问题所属校验阶段的中文名称。
StageZh string `json:"stage_zh,omitempty"`
// Code 是问题的机器可读代码。
Code string `json:"code"`
// EngineCode 是底层校验引擎提供的问题代码。
EngineCode string `json:"engine_code,omitempty"`
// Message 是问题的详细描述。
Message string `json:"message"`
// Hint 是针对问题的处理提示。
Hint string `json:"hint,omitempty"`
// File 是问题所在的包内文件路径。
File string `json:"file,omitempty"`
// Path 是问题所在的 XML 路径。
Path string `json:"path,omitempty"`
// Line 是问题所在的行号。
Line int `json:"line,omitempty"`
// Column 是问题所在的列号。
Column int `json:"column,omitempty"`
}
Issue 描述一条可定位、可机器读取的校验问题。
type Option ¶
type Option func(*Options)
Option 修改校验器配置。
func WithMaxFileSize ¶
WithMaxFileSize 设置单个 ZIP 条目解压后的大小上限。
func WithMaxInputSize ¶
WithMaxInputSize 设置 ZIP 原始输入数据的大小上限;传入 0 表示不限制。
func WithMaxTotalSize ¶
WithMaxTotalSize 设置整个 OFD 包解压后的大小上限。
type Options ¶
type Options struct {
// Mode 指定校验严格程度。
Mode Mode
// MaxErrors 指定最多记录的错误数量,0 表示不限制。
MaxErrors int
// MaxInputSize 指定 ZIP 原始输入数据的大小上限,0 表示不限制。
MaxInputSize int64
// MaxFileSize 指定单个 ZIP 条目解压后的大小上限。
MaxFileSize int64
// MaxTotalSize 指定整个 OFD 包解压后的大小上限。
MaxTotalSize int64
// MaxEntries 指定 ZIP 条目数量上限。
MaxEntries int
// MaxXMLBytes 指定单个 XML 文件的大小上限。
MaxXMLBytes int64
// MaxXMLNodes 指定单个 XML 文档的节点数量上限。
MaxXMLNodes int
// MaxXMLDepth 指定单个 XML 文档的嵌套深度上限。
MaxXMLDepth int
// CheckXSD 指定是否执行 XSD 校验。
CheckXSD bool
// ScanXML 指定是否扫描未被主引用链到达的 XML 文件。
ScanXML bool
// CheckDigest 指定是否校验签名摘要。
CheckDigest bool
// FailOnWarning 指定是否将警告视为失败。
FailOnWarning bool
// Schemas 指定使用的 XSD 模式集合。
Schemas *schema.Set
}
Options 定义校验器的资源限制和检查开关。
type PDFOptions ¶
type PDFOptions struct {
// Font 指定报告使用的字体文件;未指定时自动查找支持中文的系统字体。
Font string
}
PDFOptions 配置 PDF 报告的字体。
type Report ¶
type Report struct {
// SchemaVersion 是报告模型的版本号。
SchemaVersion string `json:"schema_version"`
// Tool 是生成报告的工具信息。
Tool ToolInfo `json:"tool"`
// Input 是被校验的输入文件信息。
Input InputInfo `json:"input"`
// Status 是整个 OFD 包的校验结论。
Status Status `json:"status"`
// StatusZh 是校验结论的中文名称。
StatusZh string `json:"status_zh,omitempty"`
// Summary 是报告中的问题和文件数量汇总。
Summary Summary `json:"summary"`
// Checks 是各校验阶段的结果列表。
Checks []CheckResult `json:"checks"`
// Issues 是校验发现的问题列表。
Issues []Issue `json:"issues"`
// StartedAt 是校验开始时间。
StartedAt time.Time `json:"started_at"`
// DurationMS 是校验耗时,单位为毫秒。
DurationMS int64 `json:"duration_ms"`
}
Report 是校验器的统一报告模型。
type Summary ¶
type Summary struct {
// Errors 是错误数量。
Errors int `json:"errors"`
// Warnings 是警告数量。
Warnings int `json:"warnings"`
// Infos 是提示数量。
Infos int `json:"infos"`
// Files 是包内文件数量。
Files int `json:"files"`
}
Summary 汇总报告中的问题和文件数量。
type ToolInfo ¶
type ToolInfo struct {
// Name 是生成报告的工具名称。
Name string `json:"name"`
// Version 是生成报告的工具版本。
Version string `json:"version"`
}
ToolInfo 描述生成报告的工具版本。
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator 执行 OFD 容器、XML、XSD、引用和语义校验。
func (*Validator) ValidatePath ¶
ValidatePath 校验指定路径的 OFD 文件并返回完整报告。
Click to show internal directories.
Click to hide internal directories.