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


Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *