paulrosenzweig / hipstersnake

Multiplayer snake in go.
56 stars 4 forks source link

Make the code go get-able #8

Open natefinch opened 11 years ago

natefinch commented 11 years ago

If you move the contents of src/snake into the repo root, and rename the imports from "snake/foo" to "github.com/paulrosenzweig/hipstersnake/foo", then a simple "go get github.com/paulrosenzweig/hipstersnake" will let fellow gophers grab and run your code with ease.

I know you just dumped the code to github after posting to HN, but it's good to keep the code in standard go format, so that fellow gophers can mess with it.

Great work, by the way! :)

paulrosenzweig commented 11 years ago

I'm still very new to Go. I've used go get to pull libraries into a project. What's the advantage of go get over git clone if it's not a go library? Thanks!

natefinch commented 11 years ago

It makes it easy to get the code up and running. Go get will put the code in a handy directory (github.com/paulrosenzweig/hipstersnake), and build the go code automatically. With the main.go file in the root directory, it'll automatically get built with the name hipstersnake.exe (or just hipstersnake on non-Windows). Right now if you build it, it'll just get built as main.exe (since that's the name of the directory it's in). You also have to know to navigate into main to build it, whereas if the go code is in the root, it'll just work automatically.

It's also just good go style to make your code go-gettable.

So... in the long run, it's minor, but it makes it easier for people to just grab your code and try it out.

paulrosenzweig commented 11 years ago

Cool. Thanks for explaining that. I couldn't quite get this working. Perhaps it's a bootstrapping problem. Since the code was not pulled with go get, how can I reference internal packages with import "github.com/paulrosenzweig/hipstersnake/foo"? Thanks for your help!

natefinch commented 11 years ago

So, everything you reference for hipstersnake will take the form "import github.com/paulrosenzweig/hisptersnake/"

The canonical way to do it would be to put your main.go in the root of the repo. This will let "go get" automatically build it (as well as allow "go build" / "go install" work from the root directory. Put the player, connection, and game directories in the root of the repo, with their files in them as they are now.

A small change to the imports: main.go would have "import github.com/paulrosenzweig/hisptersnake/connection", connection.go would have "import github.com/paulrosenzweig/hisptersnake/game" and "import github.com/paulrosenzweig/hisptersnake/player" etc.

Now everything will build and install using "go get github.com/paulrosenzweig/hisptersnake". Of course, that won't compile the coffeescript, but that's an easy second step (maybe with the deployment you have in setup.sh right now)