[ANN] gorram: like go run for any* function in stdlib or GOPATH

Skip to first unread message

Nate Finch

Oct 3, 2016, 5:00:34 PM10/3/16
to golang-nuts

get it via the canonical import path:

go get npf.io/gorram

Code is at https://github.com/natefinch/gorram

Still a work in progress, but fun to play around with right now.

Lets you do things like this:

$ echo 12345 | gorram encoding/base64.StdEncoding.EncodeToString



$ gorram encoding/json.Indent foo.json "" $'\t'


    "foo" : "bar"


or even just

$ gorram math.Sqrt 25


*does not work with every single function, if there's no obvious way to translate a CLI arg to that type.

Give it a try and give me some feedback.


Oct 5, 2016, 12:53:24 PM10/5/16
to golang-nuts
That is... awesome...

Nate Finch

Oct 5, 2016, 1:56:12 PM10/5/16
to golang-nuts, setha...@gmail.com
Glad you think so :)  Suggestions and bugs welcome.  It's under active development, and I know some things don't work right now (like variadic functions), but I'd like to make it work with as wide a swath of go functions as I can :)  And I think that, since there's such a strong culture of being idiomatic in Go, not to mention implicit interfaces, that we can make a heck of a lot of things Just Work™.

Nicola Larosa (tekNico)

Oct 6, 2016, 12:01:21 PM10/6/16
to golang-nuts
Can't stop the signal. ;-)

Nicola Larosa

Mathieu Lonjaret

Oct 7, 2016, 12:58:29 PM10/7/16
to Nate Finch, golang-nuts, setha...@gmail.com
out of curiosity, do you envision a way to make something based on

gorram net/http Get http://foo.org

"Just Work"? (i.e. it would get you what the user is most likely
interested in: the resp.Body)

I must admit it's the first thing I tried as it would have been a
gorram fun replacement for curl.
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nate Finch

Oct 7, 2016, 3:39:41 PM10/7/16
to golang-nuts, nate....@gmail.com, setha...@gmail.com
It was one of my first thoughts, too.   So, just for those who haven't tried it... it does work, technically -

$ gorram net/http Get https://google.com
&{200 OK 200 HTTP/2.0 2 0 map[Cache-Control:[private, max-age=0] Content-Type:[text/html; charset=ISO-8859-1] X-Xss-Protection:[1; mode=block] Set-Cookie:[NID=88=E2yqXfl49gKoEJYEtuL4H_FOWxG0OSrOROawAQzestRQCp0dY5cBc-vtLsu-U0ZOO9YF4ZgsuLi_yXc1WoJM-l3p06bGnOghpQiX7UNFdpfO-axDIMQsKkex90z1qSYxIUghrOSUFpPYVhI; expires=Sat, 08-Apr-2017 19:32:14 GMT; path=/; domain=.google.com; HttpOnly] X-Frame-Options:[SAMEORIGIN] Alt-Svc:[quic=":443"; ma=2592000; v="36,35,34,33,32"] Date:[Fri, 07 Oct 2016 19:32:14 GMT] Expires:[-1] P3p:[CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."] Server:[gws]] 0xc420399200 -1 [] false true map[] 0xc4203300f0 0xc4202e6840}

However, for useful output, you'd really want to show the body.  The problem is that it requires a lot of understanding of how the http.Client works.  If you get a 404 from the site, you'll get an empty body and no error... obviously what you'd want is to show the 404, and not just an empty body.  I could just hack all that into the generator code.. and maybe that would be worth the wow factor to do it... but in general, I was hoping to avoid type-specific handling and try to be more generic so I don't have to write a new handler for every possible return type.

Maybe a workable heuristic would be - if the return type has a field that is an io.Reader, try to read that reader.  If it's not empty, show that data, otherwise, just print the struct.  That's kind of a hack... I wonder how many other return values would actually follow that pattern.

Nate Finch

Oct 7, 2016, 10:05:05 PM10/7/16
to golang-nuts, nate....@gmail.com, setha...@gmail.com
...and now it works like you'd hope :)

$ gorram net/http Get https://npf.io/gorram/run
<!DOCTYPE html><html><head><link rel="canonical" href="https://npf.io/gorram/"/><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="refresh" content="0;url=https://npf.io/gorram/" /></head></html>

or if you want to get fancy:

$ gorram net/http Get https://npf.io/gorram/run | gorram github.com/yosssi/gohtml Format
<!DOCTYPE html>
    <link rel="canonical" href="https://npf.io/gorram/"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="refresh" content="0;url=https://npf.io/gorram/" />

Mathieu Lonjaret

Oct 10, 2016, 6:02:48 PM10/10/16
to Nate Finch, golang-nuts, Seth McLean
Looks shiny!
But is there some sort of cache I have to clear? I've just updated and
rebuilt, and I still get the old behaviour.

Edward Muller

Oct 11, 2016, 12:19:55 PM10/11/16
to Mathieu Lonjaret, Nate Finch, golang-nuts, Seth McLean
gorram -r <...>

Mathieu Lonjaret

Oct 11, 2016, 4:34:35 PM10/11/16
to Edward Muller, Nate Finch, golang-nuts, Seth McLean
aha! that was it, thanks.

Nate Finch

Oct 11, 2016, 4:57:52 PM10/11/16
to golang-nuts, nate....@gmail.com, setha...@gmail.com
Next on my list is adding versioning to the generated scripts so you never have to worry about whether a script is old or not.

Also note that I added -t <template> so you can print out different parts of the respond if you want, e.g.  

$ gorram -t {{.Status}} net/http Get https://golang.org
200 OK

Nate Finch

Oct 12, 2016, 10:21:02 PM10/12/16
to golang-nuts, nate....@gmail.com, setha...@gmail.com
Versioning for the scripts is now in, so no need to run with -r to regenerate scripts (
Reply all
Reply to author
0 new messages