Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is awesome. Combined with Chrome Developer Tools' "Copy request as cURL" feature, you can reverse engineer some service and turn it into Go code so easily.


Ah. That's what makes it useful. Writing

   curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582" -d '{"type":"A","name":"www","data":"162.10.66.0","priority":null,"port":null,"weight":null}' "https://api.digitalocean.com/v2/domains/example.com/records"
by hand would seem to indicate you're using the wrong tool for the job. But if other tools use curl commands as a notation for HTTP requests, curl command to programming language conversion has a real use case.


The "copy as curl" feature is very useful when doing penetration testing of a web app, because you can quickly iterate on what requests you're sending. It also helps to download large files if, like me, you don't trust browsers to download your files properly (or if you want to download something from a server).

APIs aren't the only thing HTTP is used for. Although, you could stick curl commands in shell scripts as well to have dumb API scripts.

There are use cases for every feature.


So how about a variation that takes a curl command and writes Go http server code that would accept that request?


Speaking generally, it's more difficult to do much useful with that, because it's hard to do much more than route on the URL. You could prototype code that merely looks at the mentioned headers, but it's getting kinda silly at that point.

More specific to JSON, you may be looking for something like https://mholt.github.io/json-to-go/ (by the same author) or https://github.com/ChimeraCoder/gojson (which I've used myself).

(I find that what I pay in using a static language like Go to manipulate JSON and having to use a tool like that often comes back to me pretty quickly when I take the tool output as a template and start turning all the structs into Real Objects (TM). The dynamic languages are pretty good at taking JSON and yielding a simple pile of dict/map/array/strings/numbers/etc., but if you want to get real objects back out of them the advantage over Go evaporates. Not because the dynamic languages make it "hard", but just because with one of these tools, both Go and the dynamic solutions are roughly as easy.)


Couldn't you write a program that does that trivially by writing Go http server code that accepts any request?


Agreed! Burp Suite also has the ability to copy a request as a cURL command, which can definitely help with reversing mobile device API's as well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: