Skip to content

搜索结果导出

搜索返回结构化的 []Certificate,但有时你要的是crt.sh 原汁原味的导出——喂给下游管道、做归档、做对比。SDK 提供三种导出方法,全部复用搜索参数。

FetchSearchJSONFetchSearchCSVFetchSearchAtomFeed复用 QueryParams

三种格式

📋JSON
端点 `?output=json`,返回 JSON 数组原文。程序消费、归档
📊CSV
端点 `/csv`,返回 CSV。Excel、表格工具
📡Atom
端点 `/atom`,返回解析后的 `*AtomFeed`。订阅、监控

三种方法都接收同一个 QueryParams——搜索类型、匹配模式、过滤、分组、排序、lint、分页全部可用。

流程对比

flowchart TD P["QueryParams"] --> V["Validate"] V --> B["buildQuery"] B --> J["FetchSearchJSON: 加 output=json"] B --> C["FetchSearchCSV: 去掉 output, 走 /csv"] B --> A["FetchSearchAtomFeed: 去掉 output, 走 /atom"] J --> R1["GET crt.sh?q&output=json
Accept: application/json"] C --> R2["GET crt.sh/csv?q
Accept: text/csv"] A --> R3["GET crt.sh/atom?q
Accept: atom+xml"] R1 --> VJ["json.Valid 校验"] --> S1["string"] R2 --> S2["string"] R3 --> PA["parseAtomFeed"] --> AF["*AtomFeed
(含 URL/RawXML)"]

为什么 Atom 返回结构体而非原文

JSON 和 CSV 直接返回 string——因为它们就是数据,调用方自己解析。但 Atom 是订阅语义——你会想知道 feed 的 identity、match、URL、原始 XML。

回填的元数据

FetchSearchAtomFeed 在解析后把 identity、match、URL、原始 XML 回填到 AtomFeed 结构体,省得调用方再自己拼。

go
feed, _ := client.FetchSearchAtomFeed(ctx, crtsh.QueryParams{
    Q: "example.com", ExcludeExpired: true,
})
// feed.URL      → 可直接放进 RSS 阅读器
// feed.Entries  → []AtomEntry
// feed.RawXML   → 原始 XML 串

按用途选格式

flowchart TD NEED["你要拿导出去干嘛?"] --> Q1{要程序消费?} Q1 -->|是| Q2{需要 SDK 结构化?} Q2 -->|是, 要结构化证书| SC["SearchCertificates
SDK 已 unmarshal"] Q2 -->|否,要 crt.sh 原文| JSON["FetchSearchJSON
JSON 字符串"] Q1 -->|否,给人看/Excel| CSV["FetchSearchCSV
CSV 字符串"] NEED --> Q3{要持续订阅新证书?} Q3 -->|是| ATOM["FetchSearchAtomFeed
解析后的 *AtomFeed"] Q3 -->|否| Q1

与 SearchCertificates 的区别

flowchart LR subgraph SearchCertificates S1["返回结构化 []Certificate
SDK 帮你 unmarshal"] end subgraph FetchSearchJSON S2["返回 crt.sh JSON 原文
不经 SDK 结构化"] end

何时用 FetchSearchJSON

当你怀疑 SDK 的 Certificate 结构体丢了某个字段,或要 100% 与 crt.sh 网页导出一致时,用 FetchSearchJSON