{"id":13700958,"url":"https://github.com/natefinch/gorram","last_synced_at":"2025-04-12T21:20:18.568Z","repository":{"id":144202254,"uuid":"69049016","full_name":"natefinch/gorram","owner":"natefinch","description":"It's like go run for any go function","archived":false,"fork":false,"pushed_at":"2022-11-12T05:01:40.000Z","size":94,"stargazers_count":1043,"open_issues_count":17,"forks_count":37,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-12T06:43:53.365Z","etag":null,"topics":["code-generation","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/natefinch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-23T18:05:04.000Z","updated_at":"2024-09-22T14:45:15.000Z","dependencies_parsed_at":"2023-06-01T13:16:22.473Z","dependency_job_id":null,"html_url":"https://github.com/natefinch/gorram","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natefinch%2Fgorram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natefinch%2Fgorram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natefinch%2Fgorram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natefinch%2Fgorram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/natefinch","download_url":"https://codeload.github.com/natefinch/gorram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248632244,"owners_count":21136651,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","go","golang"],"created_at":"2024-08-02T20:01:11.349Z","updated_at":"2025-04-12T21:20:18.545Z","avatar_url":"https://github.com/natefinch.png","language":"Go","readme":"# gorram [![Codeship](https://img.shields.io/codeship/ba651390-71e8-0134-7f3a-1a37cb97ae34.svg?maxAge=0)](https://app.codeship.com/projects/178461) [![Go Report Card](https://goreportcard.com/badge/npf.io/gorram)](https://goreportcard.com/report/npf.io/gorram)\n![river](https://cloud.githubusercontent.com/assets/3185864/18798443/97829e60-81a0-11e6-99a2-d8a788dd9279.jpg)\n\n\u003csup\u003e\u003csub\u003eimage: \u0026copy; [SubSuid](http://subsuid.deviantart.com/art/River-Tam-Speed-Drawing-282223915)\u003c/sub\u003e\u003c/sup\u003e\n\nIt's like go run for any go function.\n\nAutomagically understands how to produce an interface from the command line into\na Go function.\n\n*Sometimes, magic is just someone spending more time on something than anyone else might reasonably expect.* -Teller\n\n\n## Demo\n\n[![Gorram Demo](https://img.youtube.com/vi/itMAtRGLSEw/maxresdefault.jpg)](https://www.youtube.com/watch?v=itMAtRGLSEw)\n\n## Installation\n\n```\ngo get -u npf.io/gorram\n```\n\nNote: gorram depends on having a working go environment to function, since it\ndynamically analyzes go code in the stdlib and in your GOPATH.\n\n## Usage\n\n```\nUsage: gorram [OPTION] \u003cpkg\u003e \u003cfunc | var.method\u003e [args...]\n\nOptions:\n  -t \u003cstring\u003e  format output with a go template\n  -h, --help   display this help\n\nExecutes a go function or an method on a global variable defined in a package in\nthe stdlib or a package in your GOPATH.  Package must be the full package import\npath, e.g. encoding/json.  Only exported functions, methods, and variables may\nbe called.\n\nMost builtin types are supported, and streams of input (via io.Reader or []byte\nfor example) may be read from stdin.  If specified as an argument, the argument\nto a stream input is expected to be a filename.\n\nReturn values are printed to stdout.  If the function has an output argument,\nlike io.Reader or *bytes.Buffer, it is automatically passed in and then written\nto stdout.\n\nIf there's no output stream, the return value is simply written to stdout via\nfmt.Println.  If the return value is a struct that has an exported field that is\nan io.Reader (such as net/http.Request), then that will be treated as the output\nvalue, unless it's empty, in which case we fall back to printing the output\nvalue.\n\nA template specified with -t may either be a template definition (e.g.\n{{.Status}}) or a filename, in which case the contents of the file will be used\nas the template.\n\nGorram creates a script file in $GORRAM_CACHE, or, if not set, in\n$HOME/.gorram/importpath/Name.go.  Running with -r will re-generate that script\nfile, otherwise it is reused.\n\n```\n\n\n\n## Examples\n\nPretty print JSON:\n\n```\n$ echo '{ \"foo\" : \"bar\" }' | gorram encoding/json Indent \"\" $'\\t'\n{\n    \"foo\" : \"bar\"\n}\n```\n\nCalculate a sha256 sum:\n\n```\n$ gorram crypto/sha256 Sum256 foo.gz\nabcdef012345678\n```\n\n\n## How it works\n\nThe first time you run Gorram with a specific function name, Gorram analyzes the\npackage function and generates a file for use with `go run`.  Gorram\nintelligently converts stdin and/or cli arguments into arguments for the\nfunction. Output is converted similarly to stdout.  The code is cached in a\nlocal directory so that later runs don't incur the generation overhead.\n\n## Heuristics\n\nBy default, Gorram just turns CLI args into function args and prints out the\nreturn value of a function using fmt's %v.  However, there are some special\nheuristics that it uses to be smarter about inputs and outputs, based on common\ngo idioms.\n\nFor example:\n\n```\nusage:\n$ cat foo.zip | gorram crypto/sha1 Sum\nor\n$ gorram crypto/sha1 Sum foo.zip\n\nfunction:\n// crypto/sha1\nfunc Sum(data []byte) [Size]byte\n```\n\nGorram understands functions that take a single slice of bytes (or an io.Reader)\nshould read from stdin, or if an argument is specified, the argument is treated\nas a filename to be read.\n\nReturn values that are an array of bytes are understood to be intended to be\nprinted with fmt's %x, so that you get `2c37424d58` instead of `[44 55 66 77\n88]`.\n\n```\nusage:\n$ gorram encoding/json Indent foo.json \"\" $'\\t'\nor\n$ cat foo.json | gorram encoding/json Indent \"\" $'\\t'\n\nfunction:\n// encoding/json\nfunc Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error\n```\n\nGorram understands that functions with a src argument that is an io.Reader or\n[]bytes and a dst argument that is a []byte, *bytes.Buffer, or io.Writer will\nread from stdin (or use an argument as a file to open), and write what is\nwritten to dst to stdout.\n\nGorram understands that if the function returns a non-nil error, the error\nshould be written to stderr, the program exits with a non-zero exit status, and\nnothing is written to stdout.\n\nGorram understands that prefix and indent are arguments that need to be\nspecified in the command line.\n\n\n```\nusage:\n$ gorram math Cos 25\n\nfunction:\n// math\nfunc Cos(x float64) float64\n```\n\nGorram understands how to convert CLI arguments using the stringconv.Parse*\nfunctions, and will print outputs with `fmt.Printf(\"%v\\n\", val)`.\n\n\n```\nusage:\n$ echo 12345 | gorram encoding/base64 StdEncoding.EncodeToString\nMTIzNDU2Cg==\n\nfunction:\n// base64\nfunc (e *Encoding) EncodeToString(b []byte]) string\n```\nGorram understands that packages have global variables that have methods you can\ncall.\n\n```\nusage: \n$ gorram net/http Get https://google.com\n\u003csome long html output\u003e\n\nfunction:\n// net/http\nfunc Get(url string) (resp *Response, err error)\n```\n\nGorram understands that if a function returns a struct, and one of the fields of\nthe struct is an io.Reader, then it will output the contents of that reader.  \n(if there are no contents or it's nil, the result value will be printed with\n%v).\n\n## Development\n\nSee the [project page](https://github.com/natefinch/gorram/projects/1) for what's\nbeing worked on now. \n\n## Hacking\n\nGorram requires go 1.7 to run the tests (thank you subtests!)  But only requires\nit builds with earlier versions (at least 1.6, I haven't tried earlier ones, but\nthey should be fine, too).\n","funding_links":[],"categories":["Go","Repositories"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatefinch%2Fgorram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnatefinch%2Fgorram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatefinch%2Fgorram/lists"}