cURL converter · Go
cURL to Go
Paste a curl command and get a runnable Go program using net/http. Basic auth uses req.SetBasicAuth so credentials never end up in your source strings.
InputcURL command
1 secret
MethodPOST·Headers2·Body46 B· Chars 187
OutputGo · net/http(stdlib)
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
client := &http.Client{CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }}
body := strings.NewReader("{\"to\":\"+15551234567\",\"body\":\"Hello from curl\"}")
req, _ := http.NewRequest("POST", "https://api.example.com/v1/messages", body)
req.Header.Set("Authorization", "Bearer sk_test_123")
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
out, _ := io.ReadAll(resp.Body)
fmt.Println(string(out))
}Inspect
Top guides for Go
All guides →Common questions
- Why net/http and not resty?
- net/http is the standard library — no dependencies, fastest to drop into any project. If you'd like a resty variant, tell us.
- How is the body handled?
- Bodies use strings.NewReader for text and JSON. For large payloads, swap in bytes.NewReader or an io.Reader of your choice.
- Where does error handling go?
- The generated snippet panics on Do errors for brevity; wrap in your own error path for production.
- Is my curl sent anywhere?
- No. It's all client-side.
Also convert cURL to
All guides →Same parser, same idiomatic output — swap the target language whenever your stack changes. Every hub carries its own reference guides for methods, payloads, and auth.