Application development in Go

320 views Asked by At

I'm writing a web application in Go. So far I've written all base libraries I'm going to need for now and that worked out just perfect. The package structure is really handy in that aspect.

Now I'm at the point where I need to start writing the application itself, the business logic. I'm a little lost of how or where this code should go.

I've watched and read pretty much every application development tutorial/walkthrough on the official documentation page and they always write the entire domain logic in the main package/namespace.

Is this the way to Go (sorry, had to) or was it just for the sake of simplicity?

Putting the business layer into packages feels uncomfortably wrong in my opinion.

1

There are 1 answers

3
Mostafa On BEST ANSWER

No, it does not have to be all in the same package. You can easily make a new directory, put your code for that package there, and import it from your main package. It's simple as that.

You may want to look at go-tour as a simple web app that consists of a few small packages (pic, wc, ...). If you want to see organization of a big Go app see Camlistore. Both of these are written by Go Authors, so they can be considered nice examples.

I just have to say that writing small, reusable, and separate packages is very common in Go, and that reduces the size of the main codebase of apps.