Releases: antlabs/pcurl
Releases · antlabs/pcurl
v0.0.10版本
修改内容如下:
当有--data-raw选项的时候,method应该是post
感谢 @testerzhang
v0.0.9版本
新增-i, --include选项支持,提升下兼容性。
v0.0.8版本
新增两个API,把curl解析成json或者特定struct。
dump to json
package main
import (
"fmt"
"github.com/antlabs/pcurl"
"io"
"net/http"
"os"
)
func main() {
all, err := pcurl.ParseAndJSON(`curl https://api.openai.com/v1/completions -H 'Content-Type: application/json' -H 'Authorization: Bearer YOUR_API_KEY' -d '{ "model": "text-davinci-003", "prompt": "Say this is a test", "max_tokens": 7, "temperature": 0 }'`)
fmt.Printf("%s\n", all)
/*
{
"url": "https://api.openai.com/v1/completions",
"encode": {
"body": "json"
},
"body": {
"max_tokens": 7,
"model": "text-davinci-003",
"prompt": "Say this is a test",
"temperature": 0
},
"header": [
"Content-Type: application/json",
"Authorization: Bearer YOUR_API_KEY"
]
}
}
*/
dump struct
package main
import (
"fmt"
"github.com/antlabs/pcurl"
"io"
"net/http"
"os"
)
func main() {
all, err := pcurl.ParseAndObj(`curl https://api.openai.com/v1/completions -H 'Content-Type: application/json' -H 'Authorization: Bearer YOUR_API_KEY' -d '{ "model": "text-davinci-003", "prompt": "Say this is a test", "max_tokens": 7, "temperature": 0 }'`)
fmt.Printf("%s\n", all)
/*
&pcurl.Req{Method:"POST", URL:"https://api.openai.com/v1/completions", Encode:pcurl.Encode{Body:"json"}, Body:map[string]interface {}{"max_tokens":7, "model":"text-davinci-003", "prompt":"Say this is a test", "temperature":0}, Header:[]string{"Content-Type: application/json", "Authorization: Bearer YOUR_API_KEY"}}
*/
v0.0.7版本
方便继承至别的命令里面
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)
}
v0.0.6版本
v0.0.5版本
支持-G, --get选项
v0.0.4版本
v0.0.4版本内容如下
- 遇到不支持curl选项返回error
- 支持-k --insecure选项
v0.0.3版本
changlog
支持--compressed选项
v0.0.2版本
v0.0.1版本
v0.0.1版本功能如下
支持--url选项
支持-H --header 选项
支持-F --form选项
支持-X --request选项
支持-d --data选项