- Notifications
You must be signed in to change notification settings - Fork4
convert Request of fasthttp、hertz and resty to CURL command line
License
NotificationsYou must be signed in to change notification settings
li-jin-gou/http2curl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
convert Request offasthttp,hertz and net/http to CURL command line and fork frommoul/http2curl
go get github.com/li-jin-gou/http2curl
funcFastHttpDemo() {// fasthttpvarreq fasthttp.Requestreq.SetRequestURI("https://example.com/index")req.Header.SetMethod(fasthttp.MethodPost)req.SetBody([]byte(`{"a":"b"}`))req.Header.Set("Content-Type","application/json")c,_:=http2curl.GetCurlCommandFastHttp(&req)fmt.Println(c)// Output: curl -k -X 'POST' -d '{"a":"b"}' -H 'Content-Type: application/json' 'https://example.com/index' --compressed}
funcHertzDemo() {// hertzreq:=protocol.NewRequest(consts.MethodGet,"https://example.com/index",nil)req.URI().QueryArgs().Add("a","1")req.URI().QueryArgs().Add("b","2")req.Header.Set("a","2")c,_:=http2curl.GetCurlCommandHertz(req)fmt.Println(c)// Output: curl -k -X 'GET' -H 'A: 2' -H 'Host: example.com' 'https://example.com/index?a=1&b=2' --compressed}
funcNetHttpDemo() {req,_:=http.NewRequest(http.MethodPost,"https://example.com/index",bytes.NewBufferString(`{"a":"b"}`))req.Header.Set("Content-Type","application/json")c,_:=http2curl.GetCurlCommand(req)fmt.Println(c)// Output: curl -k -X 'POST' -d '{"a":"b"}' -H 'Content-Type: application/json' 'https://example.com/index' --compressed}
funcRestyDemo() {varreq*resty.Requestclient:=resty.New()resp,_:=client.R().SetHeader("Content-Type","application/json").SetBody([]byte(`{"a":"b"}`)).Post("https://example.com/index")req=resp.Requestc,_:=http2curl.GetCurlCommandResty(req)fmt.Println(c)// Output: curl -k -X 'POST' -d '{"a":"b"}' -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'User-Agent: go-resty/2.12.0 (https://github.com/go-resty/resty)' 'https://example.com/index' --compressed}
About
convert Request of fasthttp、hertz and resty to CURL command line
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.