FormatterHQ

cURL to Go Converter

Paste a curl command and get a runnable Go program that sends the same request with the standard net/http package. No third-party modules needed.

Input SHELL
Output GO
Ready.

How to use the cURL to Go Converter

  1. Paste your curl command into the input box. Line continuations with a backslash are fine.
  2. The Go code is generated automatically; click Convert if you edit the command.
  3. Read any // comments at the top of the output for flags that were not converted.
  4. Copy the code into a main.go file and run it with go run main.go.

Convert curl to Go net/http code

This curl to Go converter turns a command copied from API docs, a terminal or your browser's "Copy as cURL" menu into a complete package main program. The output uses only the standard library: net/http for the request, io to read the response, and strings, bytes or mime/multipart only when the request has a body. os is imported only for -T uploads and @file form fields.

Example

The default sample posts a JSON order with a bearer token and a 30-second --max-time. The core of the generated program looks like this:

client := &http.Client{Timeout: 30 * time.Second}
var data = strings.NewReader(`{"customer_id":42,"items":[{"sku":"MUG-01","qty":2}],"gift":false}`)
req, err := http.NewRequest("POST", "https://api.example.com/v1/orders?notify=true", data)
if err != nil {
	panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN")
resp, err := client.Do(req)

The JSON body is kept as a Go raw string literal (backticks), so quotes inside it need no escaping. If the body itself contains a backtick, the converter switches to a normal double-quoted string.

How curl flags map to Go

  • -X / --request becomes the first argument of http.NewRequest. Without it, the method is inferred the way curl does: POST when there is a body, HEAD for -I, otherwise GET.
  • -H, -A (User-Agent), -e (Referer) and -b name=value become req.Header.Set calls; when a header is repeated, the later values use req.Header.Add so none is overwritten.
  • -d, --data-raw, --data-binary, --data-urlencode and --json become a strings.NewReader body. A plain -d without a Content-Type header gets application/x-www-form-urlencoded, just like curl.
  • -F builds a multipart.Writer; @file fields are read with os.ReadFile and the boundary header comes from writer.FormDataContentType().
  • -T file becomes a PUT request whose body is the file opened with os.Open.
  • -u user:pass becomes req.SetBasicAuth.
  • -m / --max-time sets http.Client{Timeout: ...}.
  • -k adds an http.Transport with InsecureSkipVerify: true. Use it only against test servers.
  • -G moves the data into the query string.

Limitations

Go's http.Client follows up to 10 redirects by default, so the program follows redirects even when your command had no -L. Set a CheckRedirect function if you need curl's default behavior. Client certificates (--cert), proxy settings (-x) and --connect-timeout are not converted and are flagged with a comment, while retries are dropped without one. --compressed needs no code because Go's transport requests and decodes gzip automatically.

A -d @payload.json argument is replaced by a placeholder string plus a comment, since the tool cannot read files from your disk. The generated code also uses panic for errors to stay short; swap in proper error handling for production code.

Privacy

The conversion runs entirely in your browser. Bearer tokens, API keys and passwords in your command never leave the page. Need the same request in another language? Try curl to Python or curl to Rust. To type the response JSON, paste it into JSON to Go.

Frequently asked questions

Does the generated Go code need any external packages?
No. Every import comes from the Go standard library, including multipart uploads and TLS settings. You can run it with a plain go run main.go without a go.mod dependency.
How do I decode the JSON response into a struct?
Replace the io.ReadAll part with json.NewDecoder(resp.Body).Decode(&v), where v is a struct matching the response. You can generate that struct by pasting a sample response into the JSON to Go tool.
Why does my Go program follow redirects when curl did not?
That is Go's default: http.Client follows up to 10 redirects. To stop at the first response, set CheckRedirect to a function that returns http.ErrUseLastResponse.
Can I convert a command copied from Chrome DevTools?
Yes. Use "Copy as cURL (bash)" and paste it as is. Cookies passed with -b become a Cookie header, and harmless flags like --compressed are handled or skipped.
What happens with flags the converter does not understand?
Unsupported options such as --cert are listed as comments at the top of the output so you can add them by hand. Display-only flags like -s, -v and -o are silently ignored.

Last updated October 3, 2026

Related tools

cURL to Axios (Node.js) Converter Convert curl commands to Node.js axios requests with params, headers, JSON data, auth, form-data uploads and timeouts. cURL to C# Converter Convert curl commands to C# HttpClient code for .NET with headers, content types, basic auth, multipart and TLS options. cURL to PHP Guzzle Converter Convert curl commands to PHP Guzzle requests using json, form_params, multipart, query and auth options. cURL to Java Converter Convert curl commands to Java 11+ java.net.http.HttpClient code with headers, body, redirects and timeouts. cURL to JavaScript Fetch Convert curl commands into JavaScript fetch() code with method, headers, JSON body, form data, basic auth and timeouts. cURL to PHP Converter Convert curl commands into PHP code using the curl_* functions: method, headers, body, auth, cookies and SSL options. cURL to Python Requests Convert curl commands into Python requests code: headers, params, JSON or form data, files, cookies, auth and timeouts. cURL to Rust Converter Convert curl commands to Rust using the reqwest crate, with JSON bodies via serde_json, headers, auth and timeouts. Date & Time Calculator Calculate the difference between two dates or add/subtract days, weeks, months and years from a date. Docker Run to Docker Compose Convert one or more docker run commands into a docker-compose.yml: ports, volumes, env, restart, networks, healthchecks and more. File Type Checker Find out what a file really is from its content, not its name. Detects 150+ formats and warns when the extension does not match. HTTP Status Codes Searchable list of the HTTP status codes in use, from 100 to 511, with a plain explanation of when each response is used.