Go from Beginner to Expert: A Complete Guide to Learn Golang PART-13

Step-by-Step Guide to understand Naming Conventions of the Packages and Imports in Golang

Md. Faiyaj Zaman
2 min readMar 9, 2023

--

Welcome back to our tutorial on packages and imports in Golang! In the previous post, we discussed the basics of working with packages and imports in Golang. Now, let’s talk about naming conventions.

When naming packages and imports in Golang, it’s important to follow some best practices in order to make your code easy to read and understand for yourself and others.

The general rule for naming packages is to use lowercase letters and avoid using underscores or mixedCasing. It’s also a good practice to use short but descriptive names for your packages. For example, instead of naming a package “mypackage”, it’s better to name it something like “mysql” if it contains functions for working with MySQL databases.

When it comes to imports, it’s a good practice to use the full path of the package, even if you’re importing a local package. This will make it clear where the package is located and it will also help to avoid naming conflicts.

Now, let’s talk about how to avoid naming conflicts in Golang. One way to avoid naming conflicts is by using the package’s full path when importing. As mentioned before, this makes it clear where the package is located and it will also help to avoid naming conflicts.

Another way is by using package aliases. When importing a package, you can give it an alias name using the “as” keyword. This way you can use a different name for the package in your code and avoid naming conflicts.

So, to sum up, following good naming conventions for packages and imports in Golang will help make your code easy to read and understand, and will also help you to avoid naming conflicts.

Thanks for reading, and see you in the next tutorial!

--

--