Mahyar
Mahyar

Reputation: 1121

Golang rest API project structure

I just started learning/using Golang, and want to develop a restful API (starting with this great video tutorial).

Do we have a best practice for the project structure for Golang projects? (such as dropwizard's suggested project structure for java)

for example should I put the model (API request/response) in a separate directory? what is the suggested naming for API calls (equivalent to resources in dropwizard)? etc.

any suggestions/reference is appreciated

Upvotes: 2

Views: 5641

Answers (2)

Raggaer
Raggaer

Reputation: 3318

A good structure for web applications I use is the following:

└───app
    ├───config
    ├───controllers
    └───models

I think its pretty straightforward to understand

Upvotes: -3

Thaadikkaaran
Thaadikkaaran

Reputation: 5226

For rest-api i use something like below,

.
├───app
│   ├───handlers
│   |───models
|   └───app.go
|───config
└───main.go

Where,

  1. main.go - just pulls the config and bootstraps the api,
  2. config - contains the configurations,
  3. handlers - contains all the route handlers,
  4. models - contains models to carry the data,
  5. app.go - assembles the route with handlers

Upvotes: 3

Related Questions