How to handle dependecies between packages?

I have the following project structure:

What is the best way to deal with dependencies?
How would someone deal with this design? If someone can point me on where to find a solution to this situation is also very helpful.

Thank you!

Hey Mihai,
I’m not so sure what do you mean by handling dependencies between packages. Do you have a more concrete example?

Thank you for your answer.
This is something I want to build. This project will have at most 10 000 lines of code, so it will not be a big project. However, my question is about architecture.
I identify these four packages: a device package that will deal with some hardware devices, a database for persistency, a logger that will log all kinds of information regarding the software functionality, and a web interface for the user. I am not really sure about what is the best logging mechanism: to write a single file, multiple files, SQLite, or even the database I want to use for other purposes, so this topic is subject to change.
The relationship between these packages is shown in the picture above.
I did google on how people integrate the database in their projects and some are using a global variable that holds a database connection, others are using a dependency injection mechanism, or just passing around dependencies.
In many of the posts found online, people are using some kind of constructor for instantiating structures:

type Device struct {
IP string

func NewDevice(newIp string) *Device {
return &Device{newIp}

What is the best way or the most used way of designing a golang application?

The packages you design could stay in the project root folder and the Go compiler will know to take from there. You can also put your packages and your project in $GOPATH/src/ if you intend to keep and mentain your project on Github.

Regarding the logger, usually the log package from standard library is enough, otherwise you can use more complex log packages from the internet or you can write your own. However, depends of your application needs if a special logger is really neccesary.

About the database you can use for example SQLite or a SQL server like MySql. A common mistake made when working with SQL servers is creating multiple database connections wich is wrong. Instead use a global variable holding the database connection. If you use SQLite you shoud take care of concurency because only one can write at a time. If you realy need concurency on SQLite take a look over sqlitex package (se an example here).

Regarding structs, the example you found is a common way for instantiating structures and yes, is a good practice.

[LE] For web interfaces a good practice is using template package.

Thank you very much for your time!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.