mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-06-14 15:30:16 +00:00
feat: use dig for controllers
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/tinyauthapp/tinyauth/internal/service"
|
||||
"github.com/tinyauthapp/tinyauth/internal/utils"
|
||||
"github.com/tinyauthapp/tinyauth/internal/utils/logger"
|
||||
"go.uber.org/dig"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -37,25 +38,29 @@ var (
|
||||
|
||||
type ContextMiddleware struct {
|
||||
log *logger.Logger
|
||||
runtime model.RuntimeConfig
|
||||
runtime *model.RuntimeConfig
|
||||
auth *service.AuthService
|
||||
broker *service.OAuthBrokerService
|
||||
tailscale *service.TailscaleService
|
||||
}
|
||||
|
||||
func NewContextMiddleware(
|
||||
log *logger.Logger,
|
||||
runtime model.RuntimeConfig,
|
||||
auth *service.AuthService,
|
||||
broker *service.OAuthBrokerService,
|
||||
tailscale *service.TailscaleService,
|
||||
) *ContextMiddleware {
|
||||
type ContextMiddlewareInput struct {
|
||||
dig.In
|
||||
|
||||
Log *logger.Logger
|
||||
RuntimeConfig *model.RuntimeConfig
|
||||
AuthService *service.AuthService
|
||||
BrokerService *service.OAuthBrokerService
|
||||
TailscaleService *service.TailscaleService
|
||||
}
|
||||
|
||||
func NewContextMiddleware(i ContextMiddlewareInput) *ContextMiddleware {
|
||||
return &ContextMiddleware{
|
||||
log: log,
|
||||
runtime: runtime,
|
||||
auth: auth,
|
||||
broker: broker,
|
||||
tailscale: tailscale,
|
||||
log: i.Log,
|
||||
runtime: i.RuntimeConfig,
|
||||
auth: i.AuthService,
|
||||
broker: i.BrokerService,
|
||||
tailscale: i.TailscaleService,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tinyauthapp/tinyauth/internal/assets"
|
||||
"go.uber.org/dig"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -18,7 +19,12 @@ type UIMiddleware struct {
|
||||
uiFileServer http.Handler
|
||||
}
|
||||
|
||||
func NewUIMiddleware() (*UIMiddleware, error) {
|
||||
// for future use if we need to inject dependencies into the middleware
|
||||
type UIMiddlewareInput struct {
|
||||
dig.In
|
||||
}
|
||||
|
||||
func NewUIMiddleware(_ UIMiddlewareInput) (*UIMiddleware, error) {
|
||||
m := &UIMiddleware{}
|
||||
|
||||
ui, err := fs.Sub(assets.FrontendAssets, "dist")
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tinyauthapp/tinyauth/internal/utils/logger"
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
// See context middleware for explanation of why we have to do this
|
||||
@@ -21,9 +22,15 @@ type ZerologMiddleware struct {
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
func NewZerologMiddleware(log *logger.Logger) *ZerologMiddleware {
|
||||
type ZerologMiddlewareInput struct {
|
||||
dig.In
|
||||
|
||||
Log *logger.Logger
|
||||
}
|
||||
|
||||
func NewZerologMiddleware(i ZerologMiddlewareInput) *ZerologMiddleware {
|
||||
return &ZerologMiddleware{
|
||||
log: log,
|
||||
log: i.Log,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user