diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..5f7686bda3d407935b4bdd27207338db7b8e33ce --- /dev/null +++ b/README.en.md @@ -0,0 +1,112 @@ + + +# gohook + +[![Go Reference](https://pkg.go.dev/badge/github.com/lunny/gohook.svg)](https://pkg.go.dev/github.com/lunny/gohook) + +A simple and useful golang hook library. + +## Features + +* Supports multiple hook types: HTTP, Shell, Docker, Kubernetes, Slack, Telegram, DingTalk, FeiShu, WeChat, etc. +* Provides a simple configuration interface that allows users to easily define hook tasks. +* Offers flexible execution methods: synchronous, asynchronous, or periodic execution. +* Includes built-in support for commonly used hooks to reduce repetitive development work. + +## Installation + +```bash +go get github.com/lunny/gohook +``` + +## Usage + +### Basic Usage + +```go +package main + +import ( + "fmt" + "github.com/lunny/gohook" +) + +func main() { + hook := gohook.NewHook() + + // Add a shell hook + hook.AddHook(&gohook.ShellHook{ + Name: "test", + Cmd: "echo 'hello world'", + }) + + // Execute all hooks synchronously + results := hook.RunAll() + for _, result := range results { + fmt.Printf("Hook %s executed, error: %v\n", result.Name, result.Error) + } +} +``` + +### Advanced Usage + +```go +package main + +import ( + "fmt" + "github.com/lunny/gohook" +) + +func main() { + hook := gohook.NewHook() + + // Add a periodic HTTP hook + httpHook := &gohook.HTTPHook{ + Name: "http", + URL: "https://example.com", + Method: "GET", + Headers: map[string]string{"Content-Type": "application/json"}, + Interval: 10, // Run every 10 seconds + } + hook.AddHook(httpHook) + + // Add a Docker hook + dockerHook := &gohook.DockerHook{ + Name: "docker", + Image: "nginx", + ContainerOptions: map[string]string{ + "HostConfig.Memory": "268435456", + }, + } + hook.AddHook(dockerHook) + + // Execute all hooks asynchronously + hook.RunAsyncAll() + + // Wait for user input to exit + fmt.Scanln() +} +``` + +## Supported Hook Types + +| Type | Description | +|------------|----------------------------------------| +| HTTP | Sends HTTP requests | +| Shell | Executes shell commands | +| Docker | Manages Docker containers | +| Kubernetes | Interacts with Kubernetes clusters | +| Slack | Sends messages to Slack | +| Telegram | Sends messages via Telegram bot | +| DingTalk | Sends messages to DingTalk | +| FeiShu | Sends messages to FeiShu (Lark) | +| WeChat | Sends messages to WeChat Work | + +## License + +MIT License + +## Author + +lunny \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c8251bff7151aa001d04a0e9356e3082a7610687 --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ + + +# MCP Demo 项目文档 + +该项目是一个基于 Go 语言的开源项目,主要用于演示如何构建一个模块化的服务端应用,支持多种数据库配置和日志管理功能,适用于需要快速搭建服务的开发者。 + +## 项目特点 + +- 支持多环境配置(开发、测试、生产等)。 +- 集成 GORM 框架,支持 MySQL 和 Doris 数据库。 +- 提供灵活的日志系统,支持基于 zap 的日志记录。 +- 包含中间件支持,如 Gin 的日志和恢复中间件。 +- 提供统一的响应格式(Result[T])。 +- 支持工具注册和统一处理,便于扩展。 + +## 技术栈 + +- Go 1.16+ +- GORM +- Gin +- Zap +- Viper +- Docker + +## 安装与运行 + +1. **克隆项目** + ```bash + git clone https://gitee.com/liu_zy_developer/mcp-demo.git + cd mcp-demo + ``` + +2. **构建项目** + ```bash + go build -o mcp-demo cmd/main.go + ``` + +3. **使用 Docker 运行** + ```bash + docker build -t mcp-demo . + docker run -p 8888:8888 mcp-demo + ``` + +## 功能模块 + +- **配置管理**:支持不同环境配置,通过 `configs/` 目录下的 YAML 文件进行管理。 +- **数据库支持**:通过 `internal/config/cmodel/` 提供数据库连接配置,支持 MySQL 和 Doris。 +- **日志管理**:提供多级别的日志记录,支持日志文件切割。 +- **服务初始化**:包含系统、GORM、MCP 服务等初始化逻辑。 +- **中间件支持**:包括 Gin 的日志记录和异常恢复中间件。 +- **统一响应格式**:定义统一的返回结构,便于 API 接口开发。 +- **工具扩展**:通过 `McpTool` 接口支持扩展第三方工具。 + +## 使用说明 + +- 可通过修改 `configs/` 目录下的 YAML 文件来配置不同环境的参数。 +- 使用 `cmd/main.go` 中的 `main()` 函数启动服务。 +- 通过 `internal/core/server.go` 中的 `RunServer()` 启动 HTTP 服务。 +- 提供了统一的 API 响应结构,位于 `internal/model/vo/common/result.go`。 +- 支持注册自定义工具,通过 `internal/mcp/enter.go` 提供的 `RegisterTool` 进行注册。 + +## 贡献指南 + +欢迎贡献代码和改进。请遵循以下步骤: + +1. Fork 本仓库 +2. 创建新分支 (`git checkout -b feature/xxx`) +3. 提交更改 (`git commit -am 'Add some feature'`) +4. 推送分支 (`git push origin feature/xxx`) +5. 提交 Pull Request + +## 许可证 + +本项目使用 MIT 许可证。详情请查看 `LICENSE` 文件。 \ No newline at end of file