This is convenient and useful. Thanks! On Tuesday, November 27, 2018 at 8:52:26 AM UTC-5, Ben Hoyt wrote: > > Good idea -- done! The goimports way is a bit more advanced and featureful > too. > > I love how all these little tools are basically just wrappers around a > library package which does all the work, so you can reuse them in your own > code. > > -Ben > > On Sun, Nov 25, 2018 at 8:53 AM Sameer Ajmani <sam...@golang.org > <javascript:>> wrote: > >> Instead of writing your own logic to resolve missing imports, could you >> run the goimports tool? It will automatically select imports from the >> standard library and GOPATH. >> >> S >> >> On Sat, Nov 24, 2018 at 5:06 PM Ben Hoyt <ben...@gmail.com <javascript:>> >> wrote: >> >>> I just finished a little tool called "gosnip" that allows you to run >>> little snippets of Go code from the command line: >>> >>> https://github.com/benhoyt/gosnip >>> >>> To use it, just type something like: >>> >>> $ gosnip 'fmt.Println("Hello world")' >>> Hello world >>> >>> gosnip automatically adds (standard library) imports, rolls into into a >>> complete program, and uses "go run" to run it. >>> >>> To quote the "Why?" section in the README: I made gosnip because when >>> coding in Go I often want to try little snippets of code to see what they >>> do, for example, "how does format string %6.3f work again?" I could use the >>> Go playground, but it's nice to be able to use a one-line command. Also, I >>> often develop while offline on my bus commute, so don't have access to the >>> online Go playground (yes, I know it's possible to run the Go playground >>> locally). >>> >>> It was very handy to have go/parser available in the standard library, >>> and even nicer that it automatically provides the list of unresolved names >>> -- which I use to know what to import. >>> >>> "go run" isn't particularly fast for this use case, as it spawns the go >>> compiler, linker, and then the program itself. Seems to take about 250ms on >>> my macOS machine (and it's probably slower on Windows, as os/exec is >>> somewhat slower on Windows). >>> >>> If anyone knows a better way to run Go source, let me know. As much as I >>> like writing interpreters, it'd be a big job to write a Go compiler just >>> for this. In the meantime, 250ms will have to do. >>> >>> Feedback welcome! >>> >>> -Ben >>> >>> -- >>> 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 <javascript:>. >>> For more options, visit https://groups.google.com/d/optout. >>> >>
-- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.