cURL to Go Converter
Paste a cURL command and get equivalent Go code built on the standard library net/http — no third-party HTTP package needed. The parser reads the method, repeated headers, the request body, -u basic auth and cookies, then emits a complete package main with http.NewRequest, req.Header.Set calls and a client.Do round-trip. Runs entirely in your browser; nothing is uploaded.
How to use the cURL to Go Converter
Paste a cURL command into the cURL command box — the exact string a browser produces via Copy as cURL works, including backslash line continuations. Press Convert to Go (conversion also runs as you type) and the Go code appears below, ready to drop into a .go file. Click Example to load a JSON POST with an Authorization header so you can see the shape of the output, then Copy to grab it. The generated program declares package main, imports bytes, io, fmt and net/http as needed, builds the request with http.NewRequest(method, url, bytes.NewBuffer(...)), applies each header with req.Header.Set, wires req.SetBasicAuth for -u credentials, and reads the response with io.ReadAll. It compiles with go run as-is.
Converting cURL to Go with net/http
Go ships HTTP in its standard library, so most clients are written against net/http with zero external dependencies. The canonical pattern is to construct an *http.Request with http.NewRequest(method, url, body), set headers on req.Header, hand it to an *http.Client via client.Do(req), and read the returned resp.Body. A request body must satisfy io.Reader, which is why string payloads are wrapped in bytes.NewBuffer([]byte(...)) or strings.NewReader(...). This converter follows that idiom exactly so the result reads like hand-written Go.
Two gotchas trip up newcomers. First, resp.Body is an io.ReadCloser that you must close, so the generated code includes defer resp.Body.Close() immediately after the error check — skipping it leaks connections and can exhaust the keep-alive pool under load. Second, net/http sets Content-Length and the transfer encoding for you, so the converter drops any Content-Length header from the cURL command rather than hard-coding a stale value. Basic credentials from -u user:pass become req.SetBasicAuth("user", "pass") instead of a manually base64-encoded header.
Use this when you want a self-contained Go file with no module setup beyond the standard library. If you need the same request in another language, the sibling cURL to Python converter emits requests or httpx, and the multi-language cURL converter covers several targets at once.
Common use cases
- DevTools to service code — turn a browser “Copy as cURL” into a Go client for a microservice or CLI.
- No dependencies — get a working request using only the standard library, ideal for slim containers and tooling.
- API documentation — present an endpoint as idiomatic Go alongside the raw cURL example.
- Scaffolding integrations — bootstrap a third-party API call, then layer in retries, context timeouts or structs.
- Teaching net/http — show the request/response lifecycle including the required
defer resp.Body.Close(). - Porting shell scripts — move a cron job or deploy step from raw curl into a compiled Go binary.
Frequently asked questions
Does it use any external Go packages?
net/http, bytes, io and fmt — so it runs with go run and no go get.How is the request body handled?
-d / --data body is wrapped in bytes.NewBuffer([]byte(...)) so it satisfies io.Reader, and the method defaults to POST when a body is present unless -X says otherwise.Why does the code call defer resp.Body.Close()?
resp.Body is an io.ReadCloser that must be closed to free the connection. Omitting it leaks sockets, so the converter always emits it.How is -u basic auth represented?
req.SetBasicAuth("user", "pass"), which sets the correct Authorization: Basic header for you rather than encoding it by hand.