一个基于 Go 的轻量 API 聚合服务,当前主要提供两类能力:
- Bilibili 相关接口:头像、公开收藏夹、IP 归属地、直播流解析、视频信息与直链
- 通用小工具接口:随机文案、访问者信息
项目默认使用 Hertz 启动,也支持通过 gin build tag 切到 Gin。
- 纯 Go,启动简单
- Bilibili 路由按模块挂载,便于继续扩展
- 响应缓存已独立到仓库根目录
cache/包 - 支持文件缓存和进程内存缓存两种后端
- 内置接口目录页和健康检查
- Go
1.22+
- 创建配置文件
data/config.json
{
"bili": {
"Cookie": "SESSDATA=...; bili_jct=...; DedeUserID=..."
}
}- 启动服务
go run .默认监听 127.0.0.1:8080。
如需覆盖监听地址,可设置:
HOST=0.0.0.0 PORT=8080 go run .如需使用 Gin:
go run -tags gin ./bili/ 路由组默认启用缓存,缓存 key 基于请求 URI 生成。
- 默认后端:文件缓存,目录为
data/cache/ - 可选后端:内存缓存,设置
CACHE_DRIVER=memory
示例:
CACHE_DRIVER=memory go run .当前各模块 TTL:
face:1 天ip:1 天fav:10 分钟live:20 秒video:5 分钟
只缓存成功 JSON 响应和 302 重定向响应。
GET /:接口目录页GET /healthz:健康检查
GET /other/commentGET /other/visinfo
别名:
/o/cmt/o/vi
GET /bili/face/:uidGET /bili/face/:uid.:extGET /bili/fav/:media_idGET /bili/ip/:addrGET /bili/live/:cidGET /bili/video/info?aid=...|bvid=...GET /bili/video/url?aid=...|bvid=...&cid=auto&otype=json
短别名:
/b/fc/:uid/b/fc/:uid/:ext/b/fv/:media_id/b/ip/:addr/b/lv/:cid/b/v/i/b/v/u
更详细的接口说明见 API.md。
.
├── bili/ # Bilibili 模块
├── cache/ # 缓存中间件与存储实现
├── common/ # 公共类型
├── other/ # 通用工具接口
├── web/ # Web 抽象层
├── main.go # 程序入口
└── all.go # 路由装配
- 默认 Web 引擎为 Hertz,
web_engine_hertz.go生效 - 使用
-tags gin时切到web_engine_gin.go - 前端静态资源和接口详情页模板已内嵌到二进制
可用下面的命令跑当前有效测试:
env GOCACHE=$(pwd)/.cache/go-build GOMODCACHE=$(pwd)/.cache/gomod go test ./cache ./web/... ./bili/... ./other/...