Skip to content

Releases: antlabs/pcurl

v0.0.10版本

02 May 04:32
5209915
Compare
Choose a tag to compare

修改内容如下:
当有--data-raw选项的时候,method应该是post

感谢 @testerzhang

v0.0.9版本

13 Mar 15:16
c664cb4
Compare
Choose a tag to compare

新增-i, --include选项支持,提升下兼容性。

v0.0.8版本

08 Mar 14:45
Compare
Choose a tag to compare

新增两个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版本

09 Feb 08:36
Compare
Choose a tag to compare

方便继承至别的命令里面

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版本

07 Jun 07:12
60cd54c
Compare
Choose a tag to compare

支持--data-urlencode选项 #7

v0.0.5版本

02 Jun 05:22
faf2950
Compare
Choose a tag to compare

支持-G, --get选项

v0.0.4版本

19 May 14:39
ffe781b
Compare
Choose a tag to compare

v0.0.4版本内容如下

  • 遇到不支持curl选项返回error
  • 支持-k --insecure选项

v0.0.3版本

18 May 12:35
Compare
Choose a tag to compare

changlog

支持--compressed选项

v0.0.2版本

18 May 05:28
8f45d3f
Compare
Choose a tag to compare

fix #9 不传递method,会丢掉header

v0.0.1版本

17 Apr 00:45
Compare
Choose a tag to compare

v0.0.1版本功能如下

支持--url选项
支持-H --header 选项
支持-F --form选项
支持-X --request选项
支持-d --data选项