Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 1.04 KB

File metadata and controls

29 lines (23 loc) · 1.04 KB

Set of Extensios for echo framework

GoDoc Go Report Card

GormAduit middleware

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

// HasRole middleware, depends on registration of middleware.JWT
e.POST("/create-product", createProduct, middlewarex.HasRole("admin"))