momo
介绍
go语言写的实用类库
软件架构
软件架构说明
安装教程
- xxxx
- xxxx
- xxxx
使用说明
- httptool:
// DEMO
// type APIResponse struct {
// Success bool
json:"success"
// Code int json:"code"
// Data interface{} json:"data,omitempty"
// }
// func testGet(c *gin.Context) {
// // GET请求示例
// url := c.Query("url")
// httpBuilder, err := httptools.NewRequestBuilder[APIResponse](http.MethodGet, url)
// if err != nil {
// httptools.HandleApiError(c, 500, "getBuilder error", fmt.Sprintf("%+v", err))
// return
// }
// statusCode, res, err := httpBuilder.Send()
// if err != nil {
// httptools.HandleApiError(c, statusCode, "httpsend error", fmt.Sprintf("%+v", err))
// return
// }
// c.JSON(statusCode, res)
// }
// func testPost(c *gin.Context) {
// url := c.Query("url")
// // 使用构建器模式创建请求
// httpBuilder, err := httptools.NewRequestBuilder[APIResponse](http.MethodPost, url)
// if err != nil {
// httptools.HandleApiError(c, 500, "httpbuilder error", fmt.Sprintf("%+v", err))
// return
// }
// httpBuilder.WithJSONBody(map[string]interface{}{"key": "value"})
// httpBuilder.WithHeader("X-Custom-Header", "CustomValue")
// httpBuilder.WithBaseAuth("admin", "admin")
// statusCode, res, err := httpBuilder.Send()
// if err != nil {
// httptools.HandleApiError(c, statusCode, "httpsend error", fmt.Sprintf("%+v", err))
// return
// }
// c.JSON(statusCode, res)
// }
// func testDownload(c *gin.Context) {
// url := c.Query("url")
// // 使用构建器模式创建请求
// httpBuilder, err := httptools.NewRequestBuilder[APIResponse](http.MethodGet, url)
// if err != nil {
// httptools.HandleApiError(c, 500, "httpbuilder error", fmt.Sprintf("%+v", err))
// return
// }
// httpBuilder.WithHeader("X-Custom-Header", "CustomValue").WithBaseAuth("admin", "admin").SetTimeout(30)
// buffer, statusCode, err := httpBuilder.DownloadFile()
// if err != nil {
// httptools.HandleApiError(c, statusCode, "httpsend error", fmt.Sprintf("%+v", err))
// return
// }
// err = httpBuilder.SaveToDisk(buffer, "test.jpg")
// if err != nil {
// httptools.HandleApiError(c, statusCode, "saveToDisk error", fmt.Sprintf("%+v", err))
// return
// }
// c.JSON(statusCode, httpBuilder.Resp)
// }
// func PostAndUnmarshal(path string, body string, v any) error {
// req := url.NewRequest()
// req.Body = body
// r, err := requests.Post(path, req)
// if err != nil {
// fmt.Println(err)
// return err
// }
// return json.Unmarshal(r.Content, v)
// }
参与贡献
- Fork 本仓库
- 新建 Feat_xxx 分支
- 提交代码
- 新建 Pull Request
特技
- 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
- Gitee 官方博客 blog.gitee.com
- 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
- GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
- Gitee 官方提供的使用手册 https://gitee.com/help
- Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/