Creating models in GORM
In GORM, a model is a regular Go struct that represents a table in your database. We use struct tags to have more control over how struct fields map to database columns. These tags allow us to define constraints, relationships, and other properties of the fields in our model.
Let’s define a couple of example models:
type User struct {
  Username string `gorm:"uniqueIndex;not null"`
  Password string `gorm:"not null"`
  Role string `gorm:"not null;default:'user'"`
  Sessions []Session
}
type Session struct {
  Token string `gorm:"uniqueIndex;not null"`
  Expires time.Time
  UserID uint
  Username string
}
    We now have two models, User and Session, but a few interesting things are happening here. First, we define structs with fields that end up being tables and columns in our database. Also, we are establishing restrictions with struct tags, such as setting some fields to not null, some fields...