辅助函数
🧰 `pkg/api/helpers.go` — 小工具。
📁 源码:
pkg/api/helpers.go
函数
| 符号 | 源码 | 说明 |
|---|---|---|
CreateDir(path) | L15 | 建截图目录 |
GetImageContentType(filename) | L20 | 推断图片 MIME |
IsImageFile(filename) | L35 | 是否图片 |
SendJSONResponse(w, code, resp) | L41 | 统一 JSON 响应 |
UrlWithProtocol(url, https, http) | L60 | 补协议 |
UrlHasProtocol(url) | L82 | 是否已有协议 |
函数分类
下图按职责把 helpers.go 中的辅助函数归类:响应输出、目录/文件、URL 协议三条线,便于快速定位该用哪个。
SendJSONResponse
SendJSONResponse 统一封装 APIResponse(成功/失败、数据、消息),所有 handler 都用它输出,保证响应格式一致。
URL 协议处理
UrlWithProtocol/UrlHasProtocol:用户传 example.com 时补 http:// 或 https://,决定探测策略。截图端点 ensureProtocol 用它。