Show golang-nuts: okrun - a command line helper for steamrolling go run errors (such as "imported and not used")

217 views
Skip to first unread message

Rex

unread,
Oct 5, 2014, 1:11:02 AM10/5/14
to golan...@googlegroups.com
Hi all,

Not sure if this is the place to post about helpful golang tools. I looked around the different google groups and this seems to be the best for golang discussion & feedback. If this isn't the place for this kind of post, sorry and hopefully a Mod can archive this thread.

As a new gopher, who has been using go for a couple months, I've found different error messages to be challenging. And many times I have so many errors that it's disconcerting to see such a long wall of text.

I created a helper called okrun that will attempt to fix errors that it knows it can fix (unused imported pkgs). So when you're developing in Go and go run wants to remind you about unused/imported pkgs, okrun will update your file to comment out the import line, run gofmt on the file, and then re-run your code for you. Usage instructions & an example are shown in the repo's Readme as I want to be as helpful as possible.


I welcome feedback, comments, and any other helpful things you can send my way.

Thanks for reading this and I hope to contribute more to the golang community,
-Rex

Dave Cheney

unread,
Oct 5, 2014, 5:00:06 AM10/5/14
to golan...@googlegroups.com
I cannot recommend enough that go run should only be used for programs of the size that you would type into play.golang.org.

Persisting with go run and avoiding structuring your code in the expected GOPATH workspace style will only cause you pain, incompatibility, and lost time.

Dave

Rex

unread,
Oct 5, 2014, 11:28:34 AM10/5/14
to golan...@googlegroups.com
Hi Dave,

Thanks for your feedback. It is much appreciated.

What do you mean by persisting? As a new gopher, I tend to develop & debug locally at $GOPATH/src/github.com/org/project/main.go. So my pwd would be $GOPATH/src/github.com/org/project/ and I will use go run main.go. Are you suggesting that go build && ./project is the idiomatic way? In the projects I've worked on, the go run workflow has worked fine.

Dave Cheney

unread,
Oct 5, 2014, 4:16:13 PM10/5/14
to golan...@googlegroups.com
 
Are you suggesting that go build && ./project is the idiomatic way?


Yes, do that.

Nick Craig-Wood

unread,
Oct 5, 2014, 4:44:02 PM10/5/14
to golan...@googlegroups.com
On 05/10/14 21:16, Dave Cheney wrote:
> > Are you suggesting that go build && ./project is the idiomatic way?
>
> Yes, do that.

I'd say "go install && project" is even better assuming you've put
$GOPATH/bin on the $PATH. "go build" rebuilds all the dependencies
whereas "go install" only builds out of date ones which is quite
noticeable in a big project.

--
Nick Craig-Wood <ni...@craig-wood.com> -- http://www.craig-wood.com/nick

Rex

unread,
Oct 5, 2014, 8:08:14 PM10/5/14
to golan...@googlegroups.com
Great, thanks for the advice :)

I have $GOPATH/bin on my $PATH. I've been using go run and go build mostly, but I will try to use go install more often.

Dave Cheney

unread,
Oct 5, 2014, 8:30:08 PM10/5/14
to Rex, golang-nuts

I have this alias defined.

alias gb='go install -v'

And its become second nature to use it.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/RA19v18X5V4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kishore Kumar Vaishnav

unread,
Oct 5, 2014, 8:48:35 PM10/5/14
to golan...@googlegroups.com, rex...@gmail.com
Hi Rex,

This is useful when you use a simple editor with no plugins attached. GoSublime plugin does this automatically when you save the file in the Sublime editor. I do suspect that there are other IDEs which support Go has something similar plugins available. Not to criticise, but would like you to look at the other features present in these plugins which you can add to your existing okrun and make it more better. All the best.

Rex

unread,
Oct 5, 2014, 9:02:39 PM10/5/14
to golan...@googlegroups.com, rex...@gmail.com
Hi Kishore,

I use both Sublime & GoSublime, but my environment does not do this automatically. My understanding is that on top of Sublime text editor & GoSublime plugin, a person still has to install & enable goimports by adding the line "fmt_cmd": ["goimports"] in preferences. Instructions for setting up goimports are here: http://michaelwhatcott.com/gosublime-goimports/

When I built okrun, I had never heard of goimports; hence my time spent rolling up a basic solution. But for what okrun does & other features that okrun doesn't do, goimports is a better choice since it's part of go tools.

Thanks all for the helpful feedback
Reply all
Reply to author
Forward
0 new messages