ToolConvoyToolConvoyv2.6
DEV

cURL to Go — Convert cURL Commands to Go Code

Convert cURL commands to idiomatic Go code using net/http. Parses headers, cookies, and request bodies, runs entirely in your browser. No uploads, no limits.

● LOCAL · GENERATED IN YOUR TAB0 network requests from tools since page load

cURL to Go

Convert cURL commands to Go HTTP code. Works entirely in your browser — no uploads.

cURL to Go is one of three cURL-to-language converters in this toolbox, and the Go variant is the right pick when the destination is a Go service, a CLI tool, or a serverless function. Go’s net/http package is one of the more verbose HTTP clients in mainstream use — the same cURL command that becomes a 5-line Python requests snippet becomes a 15-line Go snippet — but the verbosity comes with zero dependencies, a strong type system, and the kind of static analysis that catches bugs at compile time. For a long-lived service, the verbosity is a feature, not a bug.

The non-obvious thing about cURL-to-Go is what the cURL flags actually map to. The parser here is the same curlconverter library that powers the Python and JavaScript converters in this toolbox, and the Go output follows Go’s idiomatic patterns: headers become a http.Header map, the body becomes a strings.NewReader, basic auth becomes req.SetBasicAuth, and cookies become raw header entries. The generated code compiles against any Go 1.18+ toolchain without go get for external packages. For a project that already uses a third-party HTTP client (resty, gentleman, gorequest), the output here is a starting point that you can adapt to the project’s patterns.

For a final hand-off: if the goal is testing an API in a Go service, paste the generated code into a function and add the right error handling for your context — the output uses if err != nil checks but does not add context (fmt.Errorf(\"...: %w\", err)) or structured logging. If the goal is a one-off script, the output as-is is enough. If the goal is a long-lived client, refactor the variable names, add a timeout, and consider wrapping the http.Client in a custom struct that exposes the API methods your service actually uses.

Advertisement

How to use

  1. Paste a cURL command

    Copy a cURL command from browser DevTools (Network tab > Copy as cURL), a documentation page, or your shell history. The parser handles `-H`, `-d`, `-X`, `-u`, `--cookie`, and other common flags.

  2. Read the generated Go code

    The output uses Go's standard `net/http` package — no third-party dependencies. Headers become `http.Header` map entries, the body becomes a `strings.NewReader`, and the request flows through `http.Client.Do()`.

  3. Customize the variable names

    The tool picks default variable names (`req`, `client`, `resp`). Click any name in the output to rename it. The output is a single self-contained snippet you can paste into a Go file.

Frequently asked

Does it use any third-party packages?

No — the generated code uses only the Go standard library: `net/http`, `strings`, `io`, `fmt`, and `os`. No go.mod dependencies to add, no external imports to vendor, no version-pinning concerns.

How are request bodies handled?

`-d` and `--data` flags produce a `strings.NewReader(body)` for the request body. JSON bodies are wrapped in `bytes.NewReader([]byte(body))` for safety. Form-encoded bodies are left as-is since Go's http library handles them natively.

What about cookies and authentication?

`-b 'name=value'` becomes a `Cookie` header entry. `-u 'user:pass'` becomes a basic-auth header set via `req.SetBasicAuth`. `-H 'Cookie: ...'` is preserved as a raw header, which is the form cURL emits when copying from DevTools.

Will the generated code compile?

Yes — the output is valid Go that compiles against any Go 1.18+ toolchain. Error handling uses the idiomatic `if err != nil` pattern. The response body is read into a string and printed; production code should add context-aware error handling.

Can I generate code for a complex multipart upload?

Multipart uploads (`-F`) are supported, but the output is more verbose because Go's `mime/multipart` package requires a `Writer` to build the form. The generated code is correct but not as compact as a cURL-to-Python or cURL-to-JS output.

Limitations

  • Standard library onlyThe generated code uses `net/http`. For a more fluent API, swap to a third-party library like `resty` or `gentleman` after the conversion. The tool gives you a working baseline; libraries can shorten the final code for production use.
  • No automatic retriesThe generated `http.Client` has no timeout, no retry policy, and no connection pooling tuning. Production code should wrap the client with a timeout context and a retry policy appropriate to the destination API.
  • Multipart uploads are verboseMultipart form uploads (`-F file=@path`) generate longer Go code than equivalent Python or JavaScript because Go's `mime/multipart` package requires explicit writer setup. The code works, but the snippet is less readable than for simpler requests.

Platform notes

macOS
Go 1.18+ is required for the generated code's `any` type usage. The latest Go release is the safest pick — install via Homebrew (`brew install go`) or download the .pkg from go.dev.
Windows
Go 1.18+ is required. The Windows installer from go.dev sets up GOPATH and adds `go` to PATH. The generated code works in any Go workspace without project-specific configuration.
Linux
Go 1.18+ is required. Most distros ship an older Go in their default repos; install the official .tar.gz from go.dev or use the version manager (g, gvm) to get a recent toolchain.
CLI
The same library that powers this tool is available as the `curlconverter` package on npm, with a `curlconverter --language go` CLI mode. Useful for embedding in build scripts or for batch conversion of saved cURL commands.
Web
Runs entirely client-side. Works offline once the page has loaded. The generated Go code is portable — paste it into any Go module, run `go run main.go`, and you have a working HTTP client.
Advertisement

Related tools

Advertisement