curl2code

command module
v0.0.0-...-f529c94 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2023 License: MIT Imports: 7 Imported by: 0

README

curl2code: Convert "Copy as cURL" output to code (hopefully)

Very simple tool that stickytapes a shell parser to stdin and quacks out some code to drive an HTTP client.

Can save a lot of time when using browser dev tools.

Example:

echo "curl --request GET \
  --url http://invalid/path \
  --user-agent 'FLEEB' \
  --header 'A: B C'" \
  | curl2code

Output:

client := http.Client{
	Timeout: 10 * time.Second,
}
rq, err := http.NewRequest("GET", "http://invalid/path", nil)
if err != nil {
	return err
}
rq.Header.Set("User-Agent", "FLEEB")
rq.Header.Set("A", "B C")

rs, err := client.Do(rq)
if err != nil {
	return err
}

Expectation management

This is a tool I hack on for my own amusement in an ad-hoc fashion. No stability guarantees are made, the code is not guaranteed to work, and anything may be changed, renamed or removed at any time as I see fit.

If you wish to use any of this, I strongly recommend you copy-paste pieces as-needed (including tests and license/attribution) into your own project, or fork it for your own purposes.

Bug reports are welcome, feature requests discouraged, and code contributions will not be accepted.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL