Skip to content

Commit 7bf1a21

Browse files
committed
更新文档
1 parent 0bdc950 commit 7bf1a21

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pcurl是解析curl表达式的库
1515
* 支持-k, --insecure选项
1616
* 支持-G, --get选项
1717
* 支持--data-urlencode选项
18+
* 支持内嵌到你的结构体里面,让你的cmd秒变curl
1819

1920
# 内容
2021
- [json](#json)
@@ -113,3 +114,37 @@ func main() {
113114
}
114115

115116
```
117+
118+
## 继承pcurl的选项(curl)--让你的cmd秒变curl
119+
自定义的Gen命令继续pcurl所有特性,在此基础加些自定义选项。
120+
```go
121+
type Gen struct {
122+
//curl选项
123+
pcurl.Curl
124+
125+
//自定义选项
126+
Connections string `clop:"-c; --connections" usage:"Connections to keep open"`
127+
Duration time.Duration `clop:"--duration" usage:"Duration of test"`
128+
Thread int `clop:"-t; --threads" usage:"Number of threads to use"`
129+
Latency string `clop:"--latency" usage:"Print latency statistics"`
130+
Timeout time.Duration `clop:"--timeout" usage:"Socket/request timeout"`
131+
}
132+
133+
func main() {
134+
g := &Gen{}
135+
136+
clop.Bind(&g)
137+
138+
// pcurl包里面提供
139+
req, err := g.SetClopAndRequest(clop.CommandLine)
140+
if err != nil {
141+
panic(err.Error())
142+
}
143+
144+
// 已经拿到http.Request对象
145+
// 如果是标准库直接通过Do()方法发送
146+
// 如果是裸socket,可以通过http.DumpRequestOut先转成[]byte再发送到服务端
147+
fmt.Printf("%p\n", req)
148+
}
149+
150+
```

0 commit comments

Comments
 (0)