Go (GoLang) Folder Structure

Well, there could be a lot more discussion on how to properly structure a Go project but below is the one I am currently using and I believe it really satisfies my needs (hopefully yours too).

Just like all of the projects, the main.go or the file that has your main function would be in the root of your folder. You can initiate your project by running the following command:

go mod init example/myProject

You would have the following folders and structure (assuming you are making a web project):

myProject/
├─ config/
│ ├─ ent.go
├─ controller/
│ ├─ firstController.go
│ ├─ secondController.go
├─ dto/
│ ├─ firstDto.go
│ ├─ secondDto.go
├─ ent/
├─ middleware/
│ ├─ header.go
├─ model/
│ ├─ response.go
├─ router/
│ ├─ provider.go
│ ├─ firstRouter.go
│ ├─ secondRouter.go
├─ service/
│ ├─ firstService.go
│ ├─ secondService.go
├─ util/
│ ├─ response.go
├─ main.go

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s