Convert curl to Go
Convert curl commands to Go code using the standard net/http package. curl2code runs entirely in your browser via WebAssembly — your data stays private. If you prefer a higher-level language, try our curl to Python converter. For systems programming, see curl to Rust. Below are ready-to-use Go examples.
How to copy curl from your browser
- 1
Open DevTools
Press F12 or Ctrl+Shift+I to open your browser developer tools.
- 2
Go to the Network tab
Click the Network tab and perform the action that triggers the HTTP request.
- 3
Copy as cURL
Right-click the request → Copy → Copy as cURL. Then paste it above.
Frequently Asked Questions
What is Go net/http?
Go's net/http is a production-grade HTTP client and server included in the standard library. It requires no external dependencies, supports HTTP/2 by default, and provides connection pooling, timeouts, and TLS configuration out of the box. It's the only library curl2code uses for Go — no third-party packages needed.
net/http vs third-party Go HTTP clients — which to use?
Go's net/http is powerful enough for most use cases — unlike many languages, the standard library is production-ready. Third-party options like resty add convenience (auto-retries, chaining) but add dependencies. For a similar batteries-included approach, see our curl to Rust converter (reqwest) or curl to Python.
How to handle authentication in Go?
Set the Authorization header with req.Header.Set("Authorization", "Bearer "+token). For Basic auth, use req.SetBasicAuth(user, pass) which sets the header automatically. curl2code detects -u and -H 'Authorization: ...' and generates the correct Go code.
How to send multipart form data in Go?
Use the mime/multipart package: create a writer with multipart.NewWriter(body), add fields with CreateFormField, and files with CreateFormFile. Set Content-Type to writer.FormDataContentType(). curl2code handles all -F flag conversions.
How to handle HTTP errors in Go?
Go uses explicit error returns: always check if err != nil after http.Do(req). Then check resp.StatusCode for HTTP-level errors. Always defer resp.Body.Close() to prevent resource leaks. This explicit error handling is a core Go pattern — no exceptions, no try/catch.
How to make concurrent HTTP requests in Go?
Use goroutines with sync.WaitGroup or channels. Launch each request in a goroutine with go func() { ... }(). For bounded concurrency, use a semaphore channel. Go's goroutines are lightweight — you can easily handle thousands of concurrent requests. For similar concurrency patterns, see curl to Rust.
How to set timeouts in Go HTTP client?
Set client.Timeout for the overall request deadline. For fine-grained control, use context.WithTimeout or context.WithDeadline and pass the context to http.NewRequestWithContext. curl's --connect-timeout maps to Transport.DialContext timeout, --max-time maps to client.Timeout.
How to configure a proxy in Go?
Set Transport.Proxy to http.ProxyURL(proxyUrl) on a custom http.Transport. Go also respects HTTP_PROXY and HTTPS_PROXY environment variables by default via http.ProxyFromEnvironment. curl2code converts -x and --proxy flags to the appropriate Go proxy configuration.
How to send a POST request with JSON body in Go?
Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d "{"key":"value"}" URL to Go using curl2code. The generated code uses http.Post(url, "application/json", bytes.NewBuffer(jsonData)). curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the net/http code.
How to add Bearer token authorization in Go?
Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates net/http code with the auth header: req.Header.Set("Authorization", "Bearer YOUR_TOKEN"). curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.
How to set Content-Type header in Go?
curl2code converts curl -H "Content-Type: application/json" URL to net/http code with the proper header: req.Header.Set("Content-Type", "application/json"). For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct net/http API.