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"}}
*/