momo

package module
v1.1.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

README

momo

介绍

go语言写的实用类库

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. mutool: 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) }
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddle added in v1.0.2

func CORSMiddle() igin.HandlerFunc

func ConfRouter added in v1.0.2

func ConfRouter(router igin.IRouterGroup)

func GenRouter added in v1.0.2

func GenRouter(router igin.IRouterGroup)

func JobRouter added in v1.0.2

func JobRouter(router igin.IRouterGroup)

func LogRouter added in v1.0.2

func LogRouter(router igin.IRouterGroup)

func MinRouter added in v1.0.2

func MinRouter(port int, group, secretKey string, service rbac.IRBACService) igin.Engine

func RbacRouter added in v1.0.2

func RbacRouter(router igin.IRouterGroup)

func SrvRouter added in v1.0.2

func SrvRouter(router igin.IRouterGroup)

func SysMiddle added in v1.0.2

func SysMiddle(router igin.Engine, maxCores int)

Types

type RouterBuilder added in v1.0.2

type RouterBuilder interface {
	WithPromePort(port int) RouterBuilder
	WithMode(mode string) RouterBuilder
	WithSecretKey(secretKey string) RouterBuilder
	WithService(service rbac.IRBACService) RouterBuilder
	WithAcl(acl bool) RouterBuilder
	WithAcs(acs bool) RouterBuilder
	WithLog(log bool) RouterBuilder
	Build() igin.Engine
}

func NewRouterBuilder added in v1.0.2

func NewRouterBuilder() RouterBuilder

type RouterConfig added in v1.0.2

type RouterConfig struct {
	Mode      string
	SecretKey string
	Acl       bool
	Acs       bool
	Log       bool
	Service   rbac.IRBACService
	PromePort int
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL