curl to Go Converter – Free, Online, Private
Convert a curl command into a Go program that uses net/http. The request is built with http.NewRequest and the body is a strings.Reader.
How to convert curl to Go
- Paste a curl command. Quotes and backslash continuations are parsed, not treated as raw text.
- Copy the program. It is package main and prints the status code and body.
- Replace placeholders for multipart files. -F is noted, not fully expanded into mime/multipart.
The program you get
The output is a complete main package. Imports are only the ones the command needs: fmt, io, and net/http, plus strings when there is a body, plus crypto/tls when you passed -k. http.NewRequest receives the method, the URL, and either nil or a strings.Reader of the body. Each header is req.Header.Set. -u becomes req.SetBasicAuth with the user and the password split on the first colon. The client is http.Client with a default transport, unless -k set InsecureSkipVerify, in which case the transport is written out so the bypass is visible. The response body is read with io.ReadAll and printed with the status code. Errors from NewRequest and Do panic, which is acceptable in a snippet and not in a server.
Parsing, not regular expressions
A curl converter that splits on spaces breaks the first time the URL or the JSON contains a space. This one tokenizes. Single-quoted strings are literal, double-quoted strings honor backslash escapes for quotes and dollars, and a backslash before a newline joins lines. -H Authorization: Bearer TOKEN stays one header. The URL is taken from the first bare argument or from --url. If the command used -d without -X, the method is POST, matching curl. -I becomes HEAD. -G appends the data to the query string and leaves the method as GET. A command that does not start with curl, or that has no URL, is rejected with the parser error instead of a half-built Go file.
Worked example
The sample POST becomes NewRequest with POST, the users URL, and a reader containing the JSON object. Header.Set writes Authorization and Content-Type. The body text is a raw string literal. If the JSON itself contained a backtick, the printer would split the raw string rather than emit invalid Go. The bearer token is in the source, because you put it in the command. Nothing is sent to Utilo. Delete the token before the file lands in git. The same command converted to Axios or to Python requests uses this parse and a different printer, so a header you see here should appear there too. If it does not, the header was one of the flags the Go printer still leaves as a comment.
What is left as a comment
Multipart -F fields are listed in a comment that names mime/multipart. Building a multipart writer correctly depends on which fields are files, and a wrong snippet that claims to upload a file is worse than a TODO. --compressed, cookies from a jar, proxies, and output templates are not mapped. Timeouts are not set. http.Client with no Timeout can hang, so add one before you use the program on a server. Redirects follow Go's default policy, which is not identical to curl -L. -L is parsed and does not change the client in this printer. The page is static. Your command is not logged by an application backend, because there is no application backend receiving it.
Frequently asked questions
Is the snippet a full program?
Yes. It is package main with a main function you can run after filling any multipart TODO.
Does -k disable TLS checks?
Yes, and only then. InsecureSkipVerify is written into the transport so you can see it.
Are shell variables expanded?
No. $TOKEN is not read from your environment. The characters are copied.
Why is the body a raw string?
So quotes in JSON do not need another layer of escaping. Backticks in the body are spliced out of the raw string.