{"id":41787751,"url":"https://github.com/2lovecode/graffito","last_synced_at":"2026-01-25T04:32:10.627Z","repository":{"id":139050218,"uuid":"226291529","full_name":"2lovecode/graffito","owner":"2lovecode","description":"Golang代码集。有趣的小工具，数据结构实现，设计模式实现等","archived":false,"fork":false,"pushed_at":"2026-01-17T03:36:34.000Z","size":25765,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-17T14:38:17.669Z","etag":null,"topics":["algorithm","go","golang","leetcode","redis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2lovecode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-12-06T09:23:16.000Z","updated_at":"2026-01-17T03:36:38.000Z","dependencies_parsed_at":"2023-07-19T07:45:32.218Z","dependency_job_id":"e17b3a80-c2d9-4c55-a16b-10ba53d8a19c","html_url":"https://github.com/2lovecode/graffito","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/2lovecode/graffito","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fgraffito","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fgraffito/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fgraffito/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fgraffito/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2lovecode","download_url":"https://codeload.github.com/2lovecode/graffito/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fgraffito/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28743498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T02:46:29.005Z","status":"ssl_error","status_checked_at":"2026-01-25T02:44:29.968Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","go","golang","leetcode","redis"],"created_at":"2026-01-25T04:32:09.963Z","updated_at":"2026-01-25T04:32:10.621Z","avatar_url":"https://github.com/2lovecode.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graffito - Go开发工具箱\n\n[![Go Version](https://img.shields.io/badge/Go-1.24+-00ADD8?style=flat\u0026logo=go)](https://golang.org)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\n集成常用开发工具的工具箱，例如Go在线编辑运行沙箱、时序图生成等。同时包含一些代码片段，leetcode题解，设计模式实现，算法实现等。\n\n## ✨ 功能特性\n\n### 🛠️ 开发工具 (tools)\n- **沙箱环境** - Go代码在线编辑运行沙箱\n- **时序图生成** - PlantUML时序图自动生成工具\n- **POI搜索** - 百度地图POI搜索工具\n- **图片处理** - 图片合成、水印等处理工具\n- **文件类型识别** - 通过文件头识别文件类型\n- **地理坐标转换** - 坐标系转换工具\n- **辅助工具** - 模块依赖图、Redis工具、SQL转Go、Excel处理等\n\n### 📚 学习资源 (learn)\n- **LeetCode题解** - 包含Top100和动态规划等经典题目\n- **算法实现** - 数据结构与算法实现（图、树、链表、排序等）\n- **设计模式** - 常用设计模式实现（单例、工厂、观察者、策略等）\n- **Go实践** - Go语言特性实践代码\n\n### 🔬 实验功能 (labs)\n- **实验代码** - 各种实验性功能实现\n- **CLI实践** - 命令行工具实践探索\n\n## 🚀 快速开始\n\n### 环境要求\n\n| 开发环境 | 版本 | 说明 |\n|:---:|:---:|:---:|\n| Go | 1.24+ | 必须 |\n| Java | 8+ | PlantUML功能需要 |\n\n### 安装\n\n```bash\n# 克隆项目\ngit clone https://github.com/2lovecode/graffito.git\ncd graffito\n\n# 安装依赖（使用vendor模式）\ngo mod vendor\n\n# 编译\ngo build -mod=vendor -o graffito main.go\n\n# 或使用Makefile\nmake build\n```\n\n### 使用\n\n```bash\n# 查看所有命令\n./graffito cli --help\n\n# 使用工具\n./graffito cli tools sandbox --source \"package main\\n\\nimport \\\"fmt\\\"\\n\\nfunc main() {\\n\\tfmt.Println(\\\"Hello\\\")\\n}\"\n\n# 查看学习资源\n./graffito cli learn --help\n\n# 查看实验功能\n./graffito cli labs --help\n```\n\n## 📖 使用指南\n\n### 工具类命令 (tools)\n\n#### 沙箱 (Sandbox)\n在线运行Go代码\n\n```bash\n# 从文件运行\n./graffito cli tools sandbox --file main.go\n\n# 直接运行源代码\n./graffito cli tools sandbox --source \"package main\\n\\nimport \\\"fmt\\\"\\n\\nfunc main() {\\n\\tfmt.Println(\\\"Hello\\\")\\n}\"\n```\n\n#### PlantUML\n生成时序图和UML图\n\n```bash\n./graffito cli tools plantuml\n# 监听 internal/app/plantuml/data/ 目录，自动生成图片到 images/ 目录\n```\n\n#### POI搜索\n搜索百度地图POI信息\n\n```bash\n./graffito cli tools poi \u003cak\u003e \u003c经度\u003e \u003c纬度\u003e\n```\n\n#### 辅助工具 (utils)\n\n```bash\n# 模块依赖图\n./graffito cli tools utils modg\n\n# Redis工具\n./graffito cli tools utils redis [host] [port]\n\n# SQL转Go\n./graffito cli tools utils sql2go\n\n# 其他工具\n./graffito cli tools utils --help\n```\n\n### 学习资源命令 (learn)\n\n```bash\n# LeetCode题解\n./graffito cli learn leetcode list\n\n# 算法实现\n./graffito cli learn algorithm tree\n\n# 设计模式\n./graffito cli learn pattern factory\n\n# 查看所有学习资源\n./graffito cli learn --help\n```\n\n### 实验功能命令 (labs)\n\n```bash\n# 实验代码\n./graffito cli labs experiment depends\n\n# CLI实践\n./graffito cli labs practice xsync\n\n# 查看所有实验功能\n./graffito cli labs --help\n```\n\n## 📁 项目结构\n\n```\ngraffito/\n├── cmd/                    # 应用程序入口点\n│   ├── cli/               # CLI应用程序主入口\n│   ├── demo/              # 演示代码\n│   └── tools/             # 工具程序（统一入口在internal/app/tools/utils）\n│\n├── internal/              # 内部包（不对外暴露）\n│   ├── app/               # 应用层代码\n│   │   ├── tools/         # 工具类功能（统一入口）\n│   │   ├── learning/      # 学习资源类（统一入口）\n│   │   ├── labs/          # 实验功能类（统一入口）\n│   │   ├── shared/        # 共享工具（CLI基础工具）\n│   │   └── [各功能模块]    # 具体功能实现\n│   ├── services/          # 业务服务层\n│   └── dto/               # 数据传输对象\n│\n├── pkg/                   # 可被外部导入的库代码\n│   ├── algorithm/         # 算法实现\n│   ├── pattern/           # 设计模式\n│   ├── config/            # 配置管理\n│   ├── errors/            # 错误处理\n│   ├── logging/           # 日志系统\n│   ├── fs/                # 文件系统工具\n│   └── ...\n│\n├── docs/                  # 文档（详细说明）\n└── third_party/           # 第三方资源\n```\n\n### 架构设计\n\n项目采用清晰的分层架构，将功能按领域分为三大类：\n\n1. **Tools（工具）** - 所有实用的开发工具\n2. **Learning（学习）** - 所有学习相关的资源\n3. **Labs（实验）** - 所有实验性和探索性功能\n\n每个领域都有统一的入口点，便于管理和扩展。\n\n## 🧪 测试\n\n```bash\n# 运行所有测试\nmake test\n\n# 运行测试并查看覆盖率\nmake test-cover\n\n# 运行特定包的测试\ngo test -mod=vendor ./pkg/algorithm/...\n```\n\n## 📝 开发指南\n\n### 开发环境设置\n\n```bash\n# 1. 确保Go版本 \u003e= 1.24\ngo version\n\n# 2. 克隆项目\ngit clone https://github.com/2lovecode/graffito.git\ncd graffito\n\n# 3. 安装依赖\nmake vendor\n\n# 4. 构建项目\nmake build\n```\n\n### 添加新命令\n\n1. **确定命令所属领域**\n   - 开发工具 → `internal/app/tools/` 下创建模块\n   - 学习资源 → `internal/app/learning/` 或在对应模块添加\n   - 实验功能 → `internal/app/labs/` 下创建\n\n2. **实现命令**\n   ```go\n   // internal/app/tools/myfeature/main.go\n   package myfeature\n   \n   import (\n       \"github.com/2lovecode/graffito/internal/app/shared\"\n       \"github.com/2lovecode/graffito/pkg/logging\"\n       \"github.com/spf13/cobra\"\n   )\n   \n   func NewCommand() *cobra.Command {\n       base := \u0026shared.CLIBase{}\n       return \u0026cobra.Command{\n           Use:   \"myfeature\",\n           Short: \"功能描述\",\n           Long: `详细描述和使用示例`,\n           Run: func(cmd *cobra.Command, args []string) {\n               // 使用共享工具\n               sourceCode, err := base.ReadSourceCode(file, source)\n               if err != nil {\n                   logging.Errorf(\"读取失败: %v\", err)\n                   fmt.Fprintf(cmd.ErrOrStderr(), \"错误: %v\\n\", err)\n                   return\n               }\n               // 实现逻辑...\n           },\n       }\n   }\n   ```\n\n3. **注册命令**\n   - 在对应的 `command.go` 中注册（`tools/command.go`, `learning/command.go` 或 `labs/command.go`）\n\n### 代码规范\n\n- **命名规范**：包名小写，类型名PascalCase，函数名PascalCase（导出）或camelCase（内部）\n- **格式化**：使用 `make fmt` 格式化代码\n- **代码检查**：使用 `make lint` 检查代码（需要安装 golangci-lint）\n- **测试**：编写单元测试，使用 `make test` 运行\n\n### 最佳实践\n\n**使用共享工具：**\n```go\nbase := \u0026shared.CLIBase{}\nsourceCode, err := base.ReadSourceCode(file, source)\n```\n\n**统一日志记录：**\n```go\nlogging.Infof(\"操作成功: %s\", result)\nlogging.Debugf(\"调试信息: %v\", data)\nlogging.Errorf(\"错误: %v\", err)\n```\n\n**统一错误处理：**\n```go\nif err != nil {\n    logging.Errorf(\"操作失败: %v\", err)\n    fmt.Fprintf(cmd.ErrOrStderr(), \"错误: %v\\n\", err)\n    return\n}\n```\n\n**配置管理：**\n```bash\n# 环境变量\nexport LOG_LEVEL=debug\nexport SANDBOX_TIMEOUT=60\n```\n\n```go\n// 代码中使用\nimport \"github.com/2lovecode/graffito/pkg/config\"\ncfg := config.Get()\ntimeout := cfg.Sandbox.Timeout\n```\n\n### 提交规范\n\n建议遵循 [Conventional Commits](https://www.conventionalcommits.org/)：\n- `feat:` 新功能\n- `fix:` 修复bug\n- `docs:` 文档更新\n- `refactor:` 代码重构\n- `test:` 测试相关\n- `chore:` 构建/工具相关\n\n## 🛠️ 常用命令 (Makefile)\n\n```bash\nmake build      # 编译项目\nmake test       # 运行测试\nmake test-cover # 运行测试并生成覆盖率报告\nmake clean      # 清理编译文件\nmake vendor     # 更新vendor依赖\nmake fmt        # 格式化代码\nmake lint       # 代码检查（需要安装golangci-lint）\nmake install    # 安装到系统\n```\n\n## 📋 更新日志\n\n### 最新版本\n\n**新增功能：**\n- ✨ 完善README文档，添加详细的项目介绍和使用说明\n- ✨ 添加统一的错误处理包 `pkg/errors`\n- ✨ 添加配置管理包 `pkg/config`，支持环境变量配置\n- ✨ 改进日志系统 `pkg/logging`，支持日志级别配置\n- ✨ 添加Makefile，简化常用操作\n- ✨ 优化CLI命令组织，按三大领域分类（tools/learn/labs）\n- ✨ 使用共享工具减少代码重复\n\n**改进：**\n- 🔧 重组项目结构，将功能模块统一到 `internal/app/`\n- 🔧 将工具程序移动到 `cmd/tools/`\n- 🔧 统一错误处理和日志记录\n- 🔧 完善命令帮助信息和使用示例\n\n**修复：**\n- 🐛 修复未使用的导入问题\n- 🐛 修复日志系统初始化问题\n- 🐛 修复Context超时函数类型错误\n\n## 🤝 贡献\n\n欢迎提交 Issue 和 Pull Request！\n\n1. Fork 本仓库\n2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 开启 Pull Request\n\n## 📄 许可证\n\n本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情\n\n## 🔗 相关链接\n\n- [Go官方文档](https://golang.org/doc/)\n- [Cobra文档](https://github.com/spf13/cobra)\n\n## 👨‍💻 作者\n\n- **2lovecode** - [GitHub](https://github.com/2lovecode)\n\n---\n\n⭐ 如果这个项目对你有帮助，请给个 Star！\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2lovecode%2Fgraffito","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2lovecode%2Fgraffito","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2lovecode%2Fgraffito/lists"}