# teemo **Repository Path**: damengde/teemo ## Basic Information - **Project Name**: teemo - **Description**: 斥候 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2024-11-28 - **Last Updated**: 2025-06-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: Http, HttpClient ## README # teemo #### 介绍 teemo 是一个高效、易用的 Go 语言 HTTP 客户端库,专为简化日常 HTTP 请求、微服务通信和第三方 API 对接而设计。 **主要特性:** - 泛型支持,响应类型灵活 - 链式调用,API 简洁直观 - 支持 POST、GET、PUT、DELETE 等常用请求方式 - 请求头、参数、Body 支持多种格式自动转换 - 全局与自定义日志系统,便于调试与监控 - 统一错误处理,内置常见 HTTP 状态码映射 - 基于高性能 resty 库,兼容性与扩展性强 **适用场景:** - 微服务间 HTTP 通信 - 第三方 API 对接 - 自动化测试、Mock 服务调用 - 需要灵活扩展和统一日志、错误处理的 HTTP 客户端场景 **优势:** - API 设计简洁,易于上手 - 支持高度自定义与扩展 - 代码结构清晰,易于维护 - 兼容社区主流库 resty,性能优异 #### 软件架构 teemo 采用模块化设计,核心架构如下: - **Client**:HTTP 客户端实例,负责全局配置(如超时、日志、重试等) - **Request**:泛型请求对象,支持链式设置请求头、参数、Body,并发起请求 - **Logger**:日志模块,支持全局与自定义日志级别,便于调试和慢请求监控 **主要调用流程:** 1. 通过 `teemo.New()` 创建 Client 实例(可选配置) 2. 通过 `teemo.NewRequest[T](client)` 创建请求对象,链式设置参数 3. 调用 `Post`、`Get`、`Put`、`Delete` 等方法发起请求 4. 自动解析响应为泛型类型,统一处理错误和日志 #### 安装教程 ``` go get -u git gitee.com/damengde/teemo ``` #### 使用说明 ```go import ( "context" "fmt" "gitee.com/damengde/teemo" ) type commResp struct { Code int `json:"code"` Msg string `json:"msg"` } // 发送 POST 请求示例 func postExample() { url := "http://localhost:8080/test" body := `{"param":"123"}` headers := map[string]string{"Content-Type": "application/json"} resp, err := teemo.SendHttpPostRequest[commResp](context.TODO(), url, headers, body) if err != nil { panic(err) } fmt.Println("POST响应:", resp) } // 发送 GET 请求示例 func getExample() { url := "http://localhost:8080/test" queryParams := struct { Param string `json:"param"` }{Param: "test"} headers := map[string]string{"Content-Type": "application/json"} resp, err := teemo.SendHttpGetRequest[commResp](context.TODO(), url, headers, queryParams) if err != nil { panic(err) } fmt.Println("GET响应:", resp) } // 发送 PUT 请求示例 func putExample() { url := "http://localhost:8080/test" body := `{"param":"123"}` headers := map[string]string{"Content-Type": "application/json"} resp, err := teemo.SendHttpPutRequest[commResp](context.TODO(), url, headers, body) if err != nil { panic(err) } fmt.Println("PUT响应:", resp) } // 发送 DELETE 请求示例 func deleteExample() { url := "http://localhost:8080/test" body := `{"param":"123"}` headers := map[string]string{"Content-Type": "application/json"} resp, err := teemo.SendHttpDeleteRequest[commResp](context.TODO(), url, headers, body) if err != nil { panic(err) } fmt.Println("DELETE响应:", resp) } ```