Thursday, September 8, 2022

Project & Filename Convention in Golang

In this article, we going to analyze the naming convention for the essential parts of our code.

- Project Naming

--- Package Naming

------ Files Naming

--------- Functions

--------- Structures

--------- Variables

--------- Constants



Project Naming Convention in Golang


Name your project using lower case, that is very helpful if you are working in a library. Using lowercase your imports, repository or go.mo will looks better.

Example:

github.com/gituser/project



Package Naming Convention in Golang


Try to keep the package name as short as possible, is better to use lowercase, never use camelCase, and even is not recommended to use snake_case.

For example, use:

controller

user

mypackage



Filename Convention in Golang


Like the packages, the file names should be as short as possible but use descriptive and meaningful according to the code defined inside or the purpose of the file.

Example:

account.go

configuration.go

dbconfig.go



If the file name contains more than one word, you should use snake_case.go instead of camelCase.go.


Example:

configuration.go

database.go

db_config.go

account_service.go

account_service_notification.go



0 comments:

Post a Comment