Skip to content

Convert cURL Commands to Go

A cURL command is a compact record of an HTTP request: method, URL, headers and body.

OUTPUT FORMATSHTMLJSONMarkdown

This page turns that record into a small Go program built on the standard net/http package, so you can move a request you already captured into a Go codebase without retyping it by hand.

How the converter works

The tool has two working areas. In the first, you paste the cURL command you want to convert to Go. In the second, the equivalent Go code appears, with a copy-to-clipboard button so you can drop it straight into an editor. The generated program follows a standard net/http shape: build a client, construct a request with http.NewRequest, execute it with client.Do, defer closing the response body, read the body with ioutil.ReadAll, and print the result. Errors at request construction, execution and body reading are each handled with log.Fatal.

Capture the cURL command from your browser first

Most cURL strings come from a browser's developer tools rather than from a terminal. The workflow is the same across browsers: open the network panel, reproduce the request you care about, right-click the request row, and choose the copy-as-cURL option. The converter page links to step-by-step guides for Chrome, Safari and Firefox if you want the exact menu path for your browser. Before pasting, check three things: the request method matches what you intended, the URL includes any query string, and the headers you need (authorization, content type, cookies) are present. A cURL string copied from a logged-in session can carry credentials, so treat it as sensitive.

What the generated Go code looks like

The output is a complete, compilable main package rather than a fragment. It imports fmt, io/ioutil, log and net/http, then performs the request and prints the response body. That makes it a useful starting point for a script or a small service handler. Two practical notes: ioutil.ReadAll is deprecated in newer Go versions in favour of io.ReadAll, so you may want to swap it; and the generated code does not add retries, timeouts or proxy configuration, so production use usually needs a custom http.Client with a timeout set.

Going further with Go web scraping

If your goal is scraping rather than a single request, the converter is a starting point. A linked tutorial walks through building a first scraper in Go and using the Colly library for crawling and parsing. Colly handles the request scheduling and HTML selection that the raw net/http example leaves to you.

Other cURL converters

The same cURL string can be converted to other languages and runtimes. Available converters cover CFML, Dart, Elixir, Java, JavaScript Fetch, JSON, MATLAB, NodeJS with Axios, NodeJS with fetch, NodeJS with Request, PHP, Python, R and Rust. Use the matching link when your target project is not written in Go.

Frequently asked questions

What does a cURL to Go converter do?

It reads a cURL command and produces an equivalent Go program. The output here uses the standard net/http package, so it compiles without third-party dependencies.

Does the converter execute my request?

No. It only translates the command into code. You still need to compile and run the generated program to see whether the request succeeds, and any authentication headers in the original command must remain valid.

Which browsers can I copy a cURL command from?

The page links to extraction guides for Chrome, Safari and Firefox. The general steps are the same: open developer tools, go to the network tab, trigger the request, then copy it as cURL.

Can I convert the same command to another language?

Yes. Converters are available for CFML, Dart, Elixir, Java, JavaScript Fetch, JSON, MATLAB, NodeJS with Axios, NodeJS with fetch, NodeJS with Request, PHP, Python, R and Rust.