curl to Go Converter
Convert a curl command to Go net/http code instantly in your browser. The command stays on your device.
Your curl command is converted to Go locally in your browser and never uploaded, but avoid pasting real production tokens or credentials into any tool.
Need a JavaScript version too? Try cURL to Fetch.
About cURL to Go
This curl to go converter rewrites a curl command as idiomatic Go using the standard net/http package, so you can drop an API call straight into a Go service without wiring it up by hand. As a curl to golang tool it reads flags like -X, -H, -d, --data-raw, --json, -u, -b, and -G, builds an http.NewRequest with the right method, sets each header with req.Header.Set, and wraps the body in a strings.NewReader. The generated main() reads the response with io.ReadAll and prints the status, ready to compile with go run. Use it when porting a curl test into a backend handler, a CLI, or a worker. The conversion happens in your browser, so the command and any tokens in it are processed locally on your device and never leave it.
Features
- Builds an http.NewRequest call with the method inferred from the curl flags
- Sets each -H/--header value with req.Header.Set
- Wraps a request body in strings.NewReader and adds the strings import only when needed
- Reads the response with io.ReadAll and prints res.Status and the body
- Maps -u/--user to a Basic auth header and handles cookies, user-agent, and referer
- Appends -G/--get data to the URL as a query string and sends a nil body
- Includes basic error checks after NewRequest and Do so the snippet compiles
- Copy the result or download it as request.go with one click
How to use the cURL to Go
- Paste your curl command into the cURL command box.
- Read the generated Go net/http program in the output panel.
- Check the warning banner for any flags that were adjusted or skipped.
- Click Copy, or download the file as request.go and run it with go run.
Example
Input
curl https://api.example.com/ping
Output
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api.example.com/ping"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
fmt.Println(res.Status)
fmt.Println(string(data))
}
A bodyless GET passes nil to http.NewRequest and skips the strings import.
Common errors & troubleshooting
- The compiler reports an imported and not used "strings" error. — That import is only emitted when there is a request body. If you removed the body by hand, drop the strings import too.
- You want a reusable client with timeouts instead of http.DefaultClient. — Swap http.DefaultClient for your own &http.Client{Timeout: ...}; the snippet uses the default client to stay short.
- The body is sent as raw text but your endpoint needs JSON. — The Content-Type header carries over from curl. Make sure the original command sets a JSON Content-Type or uses --json so the header is present.
Frequently asked questions
- How do I convert a curl command to Go?
- Paste the curl command into the input box and the converter renders a complete Go net/http program on the right that you can copy or download as request.go.
- Does the generated Go code use the standard library?
- Yes. It uses net/http, io, fmt, and strings from the standard library only, so there is nothing extra to go get before running it.
- How is the request body represented in Go?
- The body is wrapped in strings.NewReader and passed to http.NewRequest, and the strings import is added automatically only when a body is present.
- Can I run the output directly with go run?
- Yes. The converter emits a full package main with a main() function, basic error handling, and response printing, so go run request.go works as-is.
- Is my curl command sent to a server when I convert it to Go?
- No. The curl to go conversion runs entirely in your browser, so the command and any secrets in it stay on your device.
Related tools
- cURL to Python — Convert a curl command to Python requests code.
- cURL to PHP — Convert a curl command to PHP cURL code.
- cURL to Node.js (axios) — Convert a curl command to Node.js axios code.
- cURL to Fetch — Convert a curl command to a JavaScript fetch() call.
- API Request Client — Send HTTP requests, build headers and params, inspect responses — your last 25 requests are saved locally.
- URL Parser — Break a URL into its parts and list query parameters.
All ArrayKit tools