cURL to Go
Convert a curl command to Go net/http
About cURL to Go
Outputs a complete Go program, package main included, that sends the request with net/http from the standard library, so there is nothing to go get. -d payloads pass verbatim through strings.NewReader, each -H becomes req.Header.Set, and -F fields are gathered in url.Values. Parsing happens client-side, so your command never leaves your machine.
Category: API.
Frequently asked questions
Does the Go code need any third-party modules?
▾
No. It is a complete package main program that imports only the standard library: net/http, io and fmt, plus strings and net/url when a body or form is present. Save it as main.go and run go run main.go; io.ReadAll requires Go 1.16 or later.
Is -F converted to multipart/form-data in Go?
▾
No. -F fields are collected in url.Values and sent as formData.Encode(), a URL-encoded body, and no Content-Type header is added for it. Set Content-Type: application/x-www-form-urlencoded with req.Header.Set, or rebuild the body with mime/multipart if the API expects multipart or a file.
How are headers, -u and the request body written in Go?
▾
Each -H becomes a req.Header.Set call, and -u user:pass becomes an Authorization: Basic header with the Base64 value precomputed instead of req.SetBasicAuth. -d payloads, JSON included, are passed verbatim to strings.NewReader in a raw string literal, without encoding/json.
What does the Go program do with -k, -L and --max-time?
▾
None of them is translated; the request goes through a plain &http.Client{}. That client already follows up to 10 redirects, while -k needs a custom http.Transport with TLSClientConfig and a timeout can be set through the Client.Timeout field.