cURL to Go HTTP Client Converter
Convert cURL CLI requests into idiomatic Go net/http client requests.
- 100% free
- Private in browser
- No signup
- No watermarks
Go HTTP Client (POST)
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
url := "https://api.stripe.com/v1/charges"
payload := strings.NewReader(`amount=2000¤cy=usd`)
req, err := http.NewRequest("POST", url, payload)
if err != nil { panic(err) }
req.Header.Set("Authorization", "Basic c2tfdGVzdF9rZXk6")
client := &http.Client{}
res, err := client.Do(req)
if err != nil { panic(err) }
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil { panic(err) }
fmt.Println(string(body))
}About cURL to Go HTTP Client Converter
The cURL to Go Converter turns a cURL command into a complete Go program that sends the same request with net/http. Paste a command copied from API docs or browser DevTools and the tool reads the URL, method, -H headers, -u basic auth, cookies, user agent, and -d or --json body, then writes http.NewRequest, req.Header.Set calls, and io.ReadAll for the response. The output is a starting point: errors use panic, and form uploads with -F are not converted. Parsing happens in your browser.
How to use cURL to Go HTTP Client Converter
- Paste your command into the Input cURL Command box.
- Check the detected HTTP method shown in the Go HTTP Client heading.
- Review the generated URL, header, and payload lines.
- Click Copy Go Code and paste it into a main.go file.
Key features
- Outputs a full package main program using net/http, io, and fmt
- Reads -X, -H, -d, --data-raw, --json, -u, -A, -b, -e, and --url flags
- Converts -u user:password into a Basic Authorization header
- Joins multiple -d values with & and defaults the method to POST
- Writes the body as a raw string literal, so JSON needs no escaping
- Handles multi-line commands with backslash line continuations
Frequently asked questions
- How do I convert a cURL command to Go?
- Paste the full command, starting with curl, into the Input cURL Command box. The Go code appears below as you type, and Copy Go Code puts it on your clipboard.
- Which cURL flags does the converter understand?
- It reads -X, -H, -d and the other --data variants, --json, -u, -A, -b, -e, and --url. Flags such as -F, -G, -k, and -L are ignored, so add multipart bodies, query building, TLS settings, or redirect rules to the Go code yourself.
- Does the Go code set a Content-Type for -d data?
- No, not unless your command includes a Content-Type header. curl adds application/x-www-form-urlencoded for -d on its own, but Go does not, so add req.Header.Set("Content-Type", "application/x-www-form-urlencoded") when the server needs it. The --json flag does set Content-Type and Accept to application/json.
- How is basic auth from -u converted?
- The user:password value is Base64-encoded and written as an Authorization: Basic header. That puts the credential in your source file, so switch to req.SetBasicAuth with values from environment variables before you commit the code.
- Can I use the generated Go code in production?
- Use it as a starting point, not as finished code. It calls panic on every error, uses an http.Client with no timeout, and prints the response body to stdout. Return errors, set a Timeout, and run gofmt before shipping.
Related In-Depth Guides
Learn practical workflows, real-world examples, and expert tips in our comprehensive guides:
Password Entropy Explained: How Bits Measure Brute-Force Cracking Time
Understand Shannon entropy in passwords, character pool combinations, and how many seconds, years, or millennia it takes GPUs to crack modern passphrases.
How to Convert Docker Run Commands to Docker Compose YAML Files
A comprehensive developer guide to transforming complex docker run commands into clean, maintainable docker-compose.yml files.
Web Accessibility & Color Contrast (WCAG 2.1): How to Design AA & AAA Palettes
A practical guide to color contrast ratios, accessibility compliance, WCAG 2.1 AA/AAA standards, and building accessible UI palettes.
Rate this tool
Be the first to rate — helps others and improves this page.