Skip to content

辅助函数

🧰 `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 用它。

下一步

基于 MIT 许可发布