Designing the project's layout
So far, all the code we've written is in the main.go
file. While this works fine, it's important to make sure the code is well structured; otherwise, you'll end up with a lot of hidden dependencies and messy code (spaghetti code) when the project grows.
We will start with the data model. Let's create a models
folder so that we can store all the models structs. For now, we have one model, which is the Recipe
struct. Create a recipe.go
file under the models
folder and paste the following content:
package models import ( "time" "go.mongodb.org/mongo-driver/bson/primitive" ) // swagger:parameters recipes newRecipe type Recipe struct { //swagger:ignore ID primitive.ObjectID `json:"id" bson:"_id"` Name ...