It associate current user (if exits from JWT token) with current db refernce so when you save an entity, the CreatedBy, UpdatedBy columns got populated.
// First your entity should embed audited.AuditedModel:
type Product struct {
gorm.Model
audited.AuditedModel
code string
}
// defines the middleware rerferencing the *gorm.DB instance
e.Use(middlewarex.GormAudit(db))
// Then get gorm db reference in the handler method via:
db := middlewarex.GetGormDB(context) // context is of type echo.Context
// use the db reference to save your entity instances.// HasRole middleware, depends on registration of middleware.JWT
e.POST("/create-product", createProduct, middlewarex.HasRole("admin"))