cURL to Go Converter
Convert a common cURL command into runnable Go code built on the standard net/http package. The command is parsed locally and never executed or uploaded.
How to use it
- Paste a cURL request copied from API documentation, DevTools, Postman, or a terminal.
- Select Convert to Go or press Ctrl/⌘ + Enter.
- Review the method, URL, headers, body, authentication, and redirect policy.
- Copy the result into a
.gofile, rungofmt, and test only against an API you may access.
cURL to Go example
This example posts a JSON body with bearer authentication and follows redirects:
curl -L -X POST https://api.example.com/v1/users \
-H 'Authorization: Bearer test-token' \
-H 'Content-Type: application/json' \
-d '{"name":"Ada","active":true}'
The generated program creates a request with http.NewRequest, supplies the body through strings.NewReader, sets each header, and sends it through an http.Client. It closes the response body with defer, reads the bytes, rejects non-2xx statuses, and prints the successful response. The code is intentionally standalone and uses no third-party dependency.
Methods, headers, and request bodies
The converter supports cURL method, header, literal data, Basic authentication, HEAD, and redirect flags shared by the other Cryonel cURL tools. If a body exists without an explicit method, POST is selected to match cURL. Literal JSON and form data remain exact strings in the Go source, so conversion does not rename fields, reorder arrays, or change number values. The declared Content-Type header tells the server how to interpret those bytes.
Headers are added with request.Header.Set. A cURL --user username:password value uses request.SetBasicAuth, the standard helper that builds the Authorization header. Commands that combine --user with another Authorization header are rejected because the result would be ambiguous. Bearer tokens and API keys remain normal headers.
Redirect and error handling
Go’s default HTTP client follows redirects, while cURL requires -L. When that flag is absent, the generated client defines CheckRedirect and returns http.ErrUseLastResponse, preserving the first redirect response instead of following it. With -L, a normal client uses Go’s default redirect policy. Applications should still inspect redirect destinations before forwarding credentials to another origin.
client.Do reports transport failures such as DNS or connection errors. An HTTP 404 or 500 is still a valid response, so the generated code separately checks StatusCode and includes the response body in the fatal error. Production services may prefer typed errors and bounded diagnostic output rather than logging an entire untrusted body.
Timeouts and contexts
The converter does not invent a timeout because the original cURL command does not provide one. Production Go code should normally set http.Client.Timeout or create the request with a deadline-bearing context. Choose limits from the API’s expected connection and response times rather than copying a universal value. Reuse a long-lived client for repeated calls so connections can be pooled.
Unsupported cURL features
The first version rejects multipart forms, file-backed bodies such as @payload.json, cookie files, client certificates, insecure TLS mode, and URL-encoded data flags. Go can implement these features, but a browser converter cannot read shell files or safely infer certificate and filesystem configuration. Convert the core request first and add reviewed multipart, cookie-jar, transport, proxy, or TLS settings in the application.
Security and privacy
Real cURL commands can contain bearer tokens, Basic auth passwords, private payloads, and internal URLs. Cryonel processes the text in the current browser tab and does not call the target. Generated Go source still contains those secrets, so replace them with environment or secret-store values before committing, logging, or sharing the code.
Frequently Asked Questions
Does the generated Go code require a third-party HTTP library?
No. It uses Go's standard net/http, io, strings, fmt, and log packages.
How does the converter preserve cURL redirect behavior?
Without cURL -L, the generated http.Client returns the first redirect response. With -L, the default Go redirect policy is used.
Does Cryonel send the generated Go request?
No. Cryonel only converts the command to source code inside the browser and never calls its URL.