package-url/packageurl-go

GitHub: package-url/packageurl-go

Package URL 规范的 Go 语言实现,提供软件包标识字符串的构建与解析功能。

Stars: 73 | Forks: 61

# packageurl-go [![build](https://github.com/yuin/goldmark/actions?query=workflow:test](https://static.pigsec.cn/wp-content/uploads/repos/cas/96/96516d7a51f21139fae950e3129296fedeb5ab5f68f6a4dd1d280445b5bfdb15.svg)](https://github.com/package-url/packageurl-go/actions?query=workflow%3Atest) [![Coverage Status](https://coveralls.io/repos/github/package-url/packageurl-go/badge.svg)](https://coveralls.io/github/package-url/packageurl-go) [![PkgGoDev](https://pkg.go.dev/badge/github.com/package-url/packageurl-go)](https://pkg.go.dev/github.com/package-url/packageurl-go) [![Go Report Card](https://goreportcard.com/badge/github.com/package-url/packageurl-go)](https://goreportcard.com/report/github.com/package-url/packageurl-go) package url 规范的 Go 实现。 ## 安装 ``` go get -u github.com/package-url/packageurl-go ``` ## 版本控制 版本将遵循该规范。因此,如果规范发布为 ``1.0``。那么 ``1.x.y`` 中的所有版本都将遵循 ``1.x`` 规范。 ## 用法 ### 从部件创建 ``` package main import ( "fmt" "github.com/package-url/packageurl-go" ) func main() { instance := packageurl.NewPackageURL("test", "ok", "name", "version", nil, "") fmt.Printf("%s", instance.ToString()) } ``` ### 从字符串解析 ``` package main import ( "fmt" "github.com/package-url/packageurl-go" ) func main() { instance, err := packageurl.FromString("test:ok/name@version") if err != nil { panic(err) } fmt.Printf("%#v", instance) } ``` ## 测试 使用常规的 ``go test`` 命令进行测试。使用 ``make test`` 将拉取所有 package-url 项目之间共享的测试固件,然后执行测试。 ``` curl -Ls https://raw.githubusercontent.com/package-url/purl-spec/master/test-suite-data.json -o testdata/test-suite-data.json go test -v -cover ./... === RUN TestFromStringExamples --- PASS: TestFromStringExamples (0.00s) === RUN TestToStringExamples --- PASS: TestToStringExamples (0.00s) === RUN TestStringer --- PASS: TestStringer (0.00s) === RUN TestQualifiersMapConversion --- PASS: TestQualifiersMapConversion (0.00s) PASS github.com/package-url/packageurl-go coverage: 90.7% of statements ok github.com/package-url/packageurl-go 0.004s coverage: 90.7% of statements ``` ## 模糊测试 模糊测试使用标准的 [Go 模糊测试](https://go.dev/doc/fuzz/) 完成,该功能在 Go 1.18 中引入。 模糊测试用于检查会导致 `FromString` 发生 panic 的输入。 使用 `make fuzz` 将运行一分钟的模糊测试。 要运行更长时间的模糊测试: ``` go test -fuzztime=60m -fuzz . ``` 或者完全省略 `-fuzztime` 以无限期运行。
标签:EVTX分析, Go, Package URL, Ruby工具, 包管理, 开发库, 数据解析, 日志审计, 软件供应链