fasten-onprem/backend/pkg/web/middleware/database.go

25 lines
733 B
Go
Raw Normal View History

2022-08-25 19:26:29 -06:00
package middleware
import (
"github.com/fastenhealth/fasten-onprem/backend/pkg"
"github.com/fastenhealth/fasten-onprem/backend/pkg/config"
"github.com/fastenhealth/fasten-onprem/backend/pkg/database"
"github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus"
2022-08-25 19:26:29 -06:00
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func RepositoryMiddleware(appConfig config.Interface, globalLogger logrus.FieldLogger, eventBus event_bus.Interface) gin.HandlerFunc {
2022-08-25 19:26:29 -06:00
deviceRepo, err := database.NewRepository(appConfig, globalLogger, eventBus)
2022-08-25 19:26:29 -06:00
if err != nil {
panic(err)
}
//TODO: determine where we can call defer deviceRepo.Close()
return func(c *gin.Context) {
c.Set(pkg.ContextKeyTypeDatabase, deviceRepo)
2022-08-25 19:26:29 -06:00
c.Next()
}
}