validator

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Unlicense Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ToolVersion = "0.1.0"

ToolVersion 是校验器报告中的工具版本。

Variables

This section is empty.

Functions

func RenderJSON

func RenderJSON(w io.Writer, report Report, pretty bool) error

RenderJSON 将报告编码为 JSON;英文枚举用于机器处理,*_zh 字段提供中文标签。

func RenderMarkdown

func RenderMarkdown(w io.Writer, report Report) error

RenderMarkdown 将报告输出为中文 Markdown。

func RenderPDF

func RenderPDF(w io.Writer, report Report, options PDFOptions) error

RenderPDF 将校验报告渲染为可搜索文本的 PDF 文档。

func RenderText

func RenderText(w io.Writer, report Report) error

RenderText 将报告输出为中文纯文本。

Types

type CheckResult

type CheckResult struct {
	Name     string `json:"name"`
	NameZh   string `json:"name_zh,omitempty"`
	Status   string `json:"status"`
	StatusZh string `json:"status_zh,omitempty"`
}

CheckResult 描述一个校验阶段的结果。

type InputInfo

type InputInfo struct {
	Path string `json:"path"`
	Size int64  `json:"size"`
}

InputInfo 描述被校验的输入文件。

type Issue

type Issue struct {
	Severity   Severity `json:"severity"`
	SeverityZh string   `json:"severity_zh,omitempty"`
	Stage      Stage    `json:"stage"`
	StageZh    string   `json:"stage_zh,omitempty"`
	Code       string   `json:"code"`
	EngineCode string   `json:"engine_code,omitempty"`
	Message    string   `json:"message"`
	Hint       string   `json:"hint,omitempty"`
	File       string   `json:"file,omitempty"`
	Path       string   `json:"path,omitempty"`
	Line       int      `json:"line,omitempty"`
	Column     int      `json:"column,omitempty"`
}

Issue 描述一条可定位、可机器读取的校验问题。

type Mode

type Mode string

Mode 表示校验严格程度。

const (
	ModeStrict     Mode = "strict"
	ModeCompat     Mode = "compat"
	ModeStructural Mode = "structural"
)

type Option

type Option func(*Options)

Option 修改校验器配置。

func WithCheckDigest

func WithCheckDigest(value bool) Option

WithCheckDigest 控制是否校验签名摘要。

func WithFailOnWarning

func WithFailOnWarning(value bool) Option

WithFailOnWarning 控制是否将警告视为失败。

func WithMaxEntries

func WithMaxEntries(value int) Option

WithMaxEntries 设置 ZIP 条目数量上限。

func WithMaxErrors

func WithMaxErrors(value int) Option

WithMaxErrors 设置最多记录的错误数量;传入 0 表示不限制。

func WithMaxFileSize

func WithMaxFileSize(value int64) Option

WithMaxFileSize 设置单个 ZIP 条目解压后的大小上限。

func WithMaxInputSize

func WithMaxInputSize(value int64) Option

WithMaxInputSize 设置 ZIP 原始输入数据的大小上限;传入 0 表示不限制。

func WithMaxTotalSize

func WithMaxTotalSize(value int64) Option

WithMaxTotalSize 设置整个 OFD 包解压后的大小上限。

func WithMaxXMLBytes

func WithMaxXMLBytes(value int64) Option

WithMaxXMLBytes 设置单个 XML 文件的大小上限。

func WithMaxXMLDepth

func WithMaxXMLDepth(value int) Option

WithMaxXMLDepth 设置单个 XML 文档的嵌套深度上限。

func WithMaxXMLNodes

func WithMaxXMLNodes(value int) Option

WithMaxXMLNodes 设置单个 XML 文档的节点数量上限。

func WithMode

func WithMode(value Mode) Option

WithMode 设置校验模式。

func WithScanXML

func WithScanXML(value bool) Option

WithScanXML 控制是否扫描未被主引用链到达的 XML 文件。

func WithSchemas

func WithSchemas(value *schema.Set) Option

WithSchemas 使用调用方提供的 XSD 模式集合。

func WithSkipXSD

func WithSkipXSD(value bool) Option

WithSkipXSD 控制是否跳过 XSD 校验。

type Options

type Options struct {
	Mode          Mode
	MaxErrors     int
	MaxInputSize  int64
	MaxFileSize   int64
	MaxTotalSize  int64
	MaxEntries    int
	MaxXMLBytes   int64
	MaxXMLNodes   int
	MaxXMLDepth   int
	CheckXSD      bool
	ScanXML       bool
	CheckDigest   bool
	FailOnWarning bool
	Schemas       *schema.Set
}

Options 定义校验器的资源限制和检查开关。

type PDFOptions

type PDFOptions struct {
	// Font 指定报告使用的字体文件;未指定时自动查找支持中文的系统字体。
	Font string
}

PDFOptions 配置 PDF 报告的字体。

type Report

type Report struct {
	SchemaVersion string        `json:"schema_version"`
	Tool          ToolInfo      `json:"tool"`
	Input         InputInfo     `json:"input"`
	Status        Status        `json:"status"`
	StatusZh      string        `json:"status_zh,omitempty"`
	Summary       Summary       `json:"summary"`
	Checks        []CheckResult `json:"checks"`
	Issues        []Issue       `json:"issues"`
	StartedAt     time.Time     `json:"started_at"`
	DurationMS    int64         `json:"duration_ms"`
}

Report 是校验器的统一报告模型。

func (Report) ExitCode

func (r Report) ExitCode(failOnWarning bool) int

ExitCode 返回适合命令行使用的退出码。

func (Report) HasErrors

func (r Report) HasErrors() bool

HasErrors 报告是否包含错误。

func (Report) HasWarnings

func (r Report) HasWarnings() bool

HasWarnings 报告是否包含警告。

type Severity

type Severity string

Severity 表示单条问题的严重程度。

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
	SeverityInfo    Severity = "info"
)

type Stage

type Stage string

Stage 表示问题所属的校验阶段。

const (
	StageContainer Stage = "container"
	StageXML       Stage = "xml"
	StageXSD       Stage = "xsd"
	StageReference Stage = "reference"
	StageSemantic  Stage = "semantic"
	StageDigest    Stage = "digest"
)

type Status

type Status string

Status 表示整个 OFD 包的校验结论。

const (
	StatusValid   Status = "valid"
	StatusInvalid Status = "invalid"
	StatusPartial Status = "partial"
	StatusError   Status = "error"
)

type Summary

type Summary struct {
	Errors   int `json:"errors"`
	Warnings int `json:"warnings"`
	Infos    int `json:"infos"`
	Files    int `json:"files"`
}

Summary 汇总报告中的问题和文件数量。

type ToolInfo

type ToolInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ToolInfo 描述生成报告的工具版本。

type Validator

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

Validator 执行 OFD 容器、XML、XSD、引用和语义校验。

func New

func New(options ...Option) (*Validator, error)

New 创建一个使用内置 OFD XSD 的校验器。

func (*Validator) ValidatePath

func (v *Validator) ValidatePath(ctx context.Context, filename string) Report

ValidatePath 校验指定路径的 OFD 文件并返回完整报告。

func (*Validator) ValidateReader

func (v *Validator) ValidateReader(ctx context.Context, reader io.Reader, name string) Report

ValidateReader 校验读取器中的 OFD 数据;name 仅用于报告中的输入名称。

Jump to

Keyboard shortcuts

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