psyb0t/gofindimpl
GitHub: psyb0t/gofindimpl
一个 Go 语言命令行工具,利用原生类型检查器在指定目录中精确查找某 interface 的所有 struct 实现,替代低效的手动 grep。
Stars: 2 | Forks: 0
# gofindimpl 🔍
[](https://pkg.go.dev/github.com/psyb0t/gofindimpl)
[](https://github.com/psyb0t/gofindimpl/actions/workflows/pipeline.yml)
[](https://github.com/psyb0t/gofindimpl/actions/workflows/pipeline.yml)
[](https://github.com/psyb0t/gofindimpl/tags)
[](LICENSE)
像一条充满怀疑的寻血猎犬一样,揪出 Go interface 的实现。
厌倦了在成千上万行代码中用 `grep` 搜索,试图弄清楚到底哪些 struct 实现了那个该死的 interface?这个工具能帮你完成这些繁重的工作,让你不用在凌晨三点再经历一次怀疑人生的危机。
## 安装 🚀
### 选项 1:安装它
```
go install github.com/psyb0t/gofindimpl@latest
```
### 选项 2:直接运行(无需安装)
```
go run github.com/psyb0t/gofindimpl@latest \
-interface ./path/to/file.go:InterfaceName \
-dir ./search/directory
```
### 选项 3:像 2005 年那样克隆并构建
```
git clone https://github.com/psyb0t/gofindimpl.git
cd gofindimpl
go build -o gofindimpl
```
## 用法 💀
### 基础查找(已安装)
```
gofindimpl \
-interface ./path/to/file.go:InterfaceName \
-dir ./search/directory
```
### 基础查找(直接运行)
```
go run github.com/psyb0t/gofindimpl@latest \
-interface ./path/to/file.go:InterfaceName \
-dir ./search/directory
```
### 实际示例(已安装)
```
gofindimpl -interface ./internal/app/server.go:Server -dir ./internal/pkg/
```
### 实际示例(直接运行)
```
go run github.com/psyb0t/gofindimpl@latest \
-interface ./internal/app/server.go:Server \
-dir ./internal/pkg/
```
### 开启 Debug 日志(专为受虐狂准备)
```
# 已安装
gofindimpl \
-interface ./internal/app/server.go:Server \
-dir ./internal/pkg/ \
-debug
# 直接运行
go run github.com/psyb0t/gofindimpl@latest \
-interface ./internal/app/server.go:Server \
-dir ./internal/pkg/ \
-debug
```
## 输出格式 📋
JSON,因为 XML 是留给那些自我折磨的人的:
```
[
{
"package": "impl",
"struct": "WebServer",
"packagePath": "github.com/yourproject/internal/pkg/impl"
},
{
"package": "mock",
"struct": "MockServer",
"packagePath": "github.com/yourproject/internal/pkg/mock"
}
]
```
## 工作原理 🧠
1. **解析 Interface**:读取指定的 Go 文件并提取 interface 方法
2. **扫描目录**:递归遍历 Go 文件(出于某些原因跳过测试文件)
3. **类型检查**:使用 Go 的类型检查器验证方法签名
4. **匹配方法**:找出实现了所有 interface 方法的 struct
5. **输出结果**:吐出包含实现细节的 JSON
## 环境要求 ✅
- **Go 1.24+**:因为活在过去是历史学家的事
- **go.mod**:必须在合法的 Go module 根目录下运行(而不是某个无政府主义的野目录)
- **合法的 Go 代码**:糟糕的语法会让这个工具哭泣
## 功能 🎯
- **方法集分析**:同时检查值接收者和指针接收者方法
-. **递归搜索**:像一只意志坚定的蜘蛛一样在目录中爬行
- **类型安全**:使用 Go 原生类型检查器,而不是令人抓狂的正则表达式
- **包过滤**:自动跳过 vendor 目录和隐藏文件夹
- **错误处理**:优雅地报错,而不是在你面前崩溃
- **Debug 模式**:当出现问题时,你可以用它来查明原因
## 命令行选项 🛠️
| 参数 | 类型 | 默认值 | 描述 |
| ------------ | ------ | -------- | --------------------------------------- |
| `-interface` | string | 必填 | Interface 规格:`file.go:InterfaceName` |
| `-dir` | string | `.` | 搜索实现的目录 |
| `-debug` | bool | `false` | 开启 debug 日志 |
| `-help` | bool | `false` | 显示帮助信息并退出 |
## 错误信息 💥
这个工具会确切地告诉你哪里出了问题,而不是让你瞎猜:
- **找不到 Interface 文件**:检查你的文件路径
- **文件中找不到 Interface**:确保该 interface 名称确实存在
- **找不到 go.mod**:请在合法的 Go module 根目录下运行
- **找不到目录**:搜索的目录不存在
- **解析错误**:请先修复你的 Go 语法
## 测试覆盖率 🧪
当前覆盖率:**90.8%**
因为没经过测试的代码就像是无保护……好吧,你懂的。
## 许可证 📜
MIT —— 因为 pkg.go.dev 那帮公司的混蛋根本不索引 WTFPL 的包。
标签:EVTX分析, Go, Ruby工具, SOC Prime, 代码分析, 代码搜索, 凭证管理, 动态分析, 开发工具, 接口查找, 文档结构分析, 日志审计