samber/go-pkggodev-client

GitHub: samber/go-pkggodev-client

为 pkg.go.dev API 提供类型化的 Go 客户端,支持包搜索、文档查询、版本列举和漏洞信息获取,并内置自动分页迭代器。

Stars: 0 | Forks: 0

# pkg.go.dev 的类型化 Go 客户端 [![tag](https://img.shields.io/github/tag/samber/go-pkggodev-client.svg)](https://github.com/samber/go-pkggodev-client/releases) ![Go 版本](https://img.shields.io/badge/Go-%3E%3D%201.25-%23007d9c) [![GoDoc](https://godoc.org/github.com/samber/go-pkggodev-client?status.svg)](https://pkg.go.dev/github.com/samber/go-pkggodev-client) ![构建状态](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/8acf9867f5020903.svg) [![Go 报告](https://goreportcard.com/badge/github.com/samber/go-pkggodev-client)](https://goreportcard.com/report/github.com/samber/go-pkggodev-client) [![贡献者](https://img.shields.io/github/contributors/samber/go-pkggodev-client)](https://github.com/samber/go-pkggodev-client/graphs/contributors) [![许可证](https://img.shields.io/github/license/samber/go-pkggodev-client)](./LICENSE) 一个针对 [pkg.go.dev](https://pkg.go.dev) API(即 "Go Pkgsite API", `https://pkg.go.dev/v1beta`)的类型化 Go 客户端:搜索包和符号,阅读文档,列出版本、 importer 和已知漏洞。 公共 API 位于模块根目录(`package pkggodev`):**context 优先的方法**、 **函数式选项**、**简洁的类型化结果**(无代码生成泄漏)以及**自动分页 迭代器**。它封装了由 [ogen](https://github.com/ogen-go/ogen) 生成、位于 [`internal/api`](internal/api) 下的客户端。 ## 🚀 安装 ``` go get github.com/samber/go-pkggodev-client ``` 该库目前为 v0 版本并遵循 SemVer。它兼容 Go >= 1.25(使用了 `iter.Seq2`)。 ## 💡 快速开始 ``` import pkggodev "github.com/samber/go-pkggodev-client" c, err := pkggodev.New(pkggodev.WithUserAgent("my-app/1.0")) if err != nil { panic(err) } // Single object. pkg, _ := c.Package(ctx, "github.com/samber/lo") fmt.Println(pkg.Path, pkg.Synopsis) // clean strings, no Opt wrappers // One page. page, _ := c.Versions(ctx, "github.com/samber/lo", pkggodev.WithLimit(10)) fmt.Println(page.Total, page.NextToken) // All results, auto-paginated. for v, err := range c.AllVersions(ctx, "github.com/samber/lo") { if err != nil { break } fmt.Println(v.Version, v.CommitTime) } ``` ## 🧠 规范 GoDoc: [https://pkg.go.dev/github.com/samber/go-pkggodev-client](https://pkg.go.dev/github.com/samber/go-pkggodev-client) ### 客户端构造函数 ``` func New(opts ...ClientOption) (*Client, error) ``` - `WithBaseURL(url)` — 覆盖 API 的 base URL。 - `WithHTTPClient(*http.Client)` — 自定义超时 / transport。 - `WithUserAgent(string)` — 设置 `User-Agent` header。 ### 方法 所有方法都首先接收 `context.Context` 并返回简洁的类型化值: | 方法 | 返回值 | | -------------------------------- | ---------------------- | | `Search(ctx, opts...)` | `*Page[SearchResult]` | | `Package(ctx, path, opts...)` | `*Package` | | `ImportedBy(ctx, path, opts...)` | `*ImportedByResult` | | `Packages(ctx, path, opts...)` | `*PackagesResult` | | `Module(ctx, path, opts...)` | `*Module` | | `Versions(ctx, path, opts...)` | `*Page[ModuleVersion]` | | `Symbols(ctx, path, opts...)` | `*Page[Symbol]` | | `Vulns(ctx, path, opts...)` | `*Page[Vulnerability]` | ### 调用选项 `WithVersion`, `WithModule`, `WithLimit`, `WithToken`, `WithFilter`, `WithGOOS`, `WithGOARCH`, `WithDoc`, `WithQuery`, `WithSymbol`, `WithExamples`, `WithImports`, `WithLicenses`, `WithReadme`. 每个方法都会忽略对其不适用的选项。 ### 迭代器(自动分页) 每个列表 endpoint 都有一个 `All…` 变体,返回一个 Go 1.25 的 `iter.Seq2[T, error]`,它会 在各个页面之间惰性地追踪 `NextToken`: `AllSearch`, `AllVersions`, `AllVulns`, `AllSymbols`, `AllPackages`, `AllImportedBy`。 ``` for v, err := range c.AllVersions(ctx, "github.com/samber/lo") { if err != nil { return err } fmt.Println(v.Version, v.CommitTime) } ``` `WithLimit` 控制页面大小;`WithToken` 设置起始游标。 ## 📝 许可证 Copyright © 2026 [Samuel Berthe](https://github.com/samber)。 本项目基于 [MIT](./LICENSE) 许可证。
标签:API客户端, EVTX分析, Go, pkg.go.dev, Ruby工具, SOC Prime, 包管理, 开发工具, 日志审计