From 7bf1a2180b0a70b279fdf8e4f24ca9010c192bc0 Mon Sep 17 00:00:00 2001 From: guonaihong Date: Tue, 9 Feb 2021 16:35:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 016938f..93821f3 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ pcurl是解析curl表达式的库 * 支持-k, --insecure选项 * 支持-G, --get选项 * 支持--data-urlencode选项 +* 支持内嵌到你的结构体里面,让你的cmd秒变curl # 内容 - [json](#json) @@ -113,3 +114,37 @@ func main() { } ``` + +## 继承pcurl的选项(curl)--让你的cmd秒变curl +自定义的Gen命令继续pcurl所有特性,在此基础加些自定义选项。 +```go +type Gen struct { + //curl选项 + pcurl.Curl + + //自定义选项 + Connections string `clop:"-c; --connections" usage:"Connections to keep open"` + Duration time.Duration `clop:"--duration" usage:"Duration of test"` + Thread int `clop:"-t; --threads" usage:"Number of threads to use"` + Latency string `clop:"--latency" usage:"Print latency statistics"` + Timeout time.Duration `clop:"--timeout" usage:"Socket/request timeout"` +} + +func main() { + g := &Gen{} + + clop.Bind(&g) + + // pcurl包里面提供 + req, err := g.SetClopAndRequest(clop.CommandLine) + if err != nil { + panic(err.Error()) + } + + // 已经拿到http.Request对象 + // 如果是标准库直接通过Do()方法发送 + // 如果是裸socket,可以通过http.DumpRequestOut先转成[]byte再发送到服务端 + fmt.Printf("%p\n", req) +} + +```