O'Reilly logo

Microservice Patterns and Best Practices by Vinicius Feitosa Pacheco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The models.go file

Starting with the models is always interesting, because it is the best place to understand the business of a project.

At first, we declare the package on which we are working, and then the imports required for the project, as follows:

    package main    import ( 
      "github.com/jmoiron/sqlx" 
      "golang.org/x/crypto/bcrypt" 
    ) 

Then, we make the declaration of our entity, Users. Go does not have classes, but instead uses structs. The final behavior is very similar to the OOP, of course, but there are peculiarities.

  • User is the struct responsible to represent the database entity:
 type User struct { ID int `json:"id" db:"id"` Name string `json:"name" db:"name"` Email string `json:"email" db:"email"` Password string `json:"password" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required