refactor: use dependency injection

This commit is contained in:
Stavros
2025-01-21 18:41:06 +02:00
parent 2988b5f22f
commit 5e73d06fcc
6 changed files with 113 additions and 42 deletions

View File

@@ -8,7 +8,17 @@ import (
"github.com/gin-gonic/gin"
)
func UseUserContext(c *gin.Context, userList types.UserList) (types.UserContext) {
func NewHooks(auth *auth.Auth) *Hooks {
return &Hooks{
Auth: auth,
}
}
type Hooks struct {
Auth *auth.Auth
}
func (hooks *Hooks) UseUserContext(c *gin.Context) (types.UserContext) {
session := sessions.Default(c)
cookie := session.Get("tinyauth")
@@ -28,7 +38,7 @@ func UseUserContext(c *gin.Context, userList types.UserList) (types.UserContext)
}
}
user := auth.FindUser(userList, username)
user := hooks.Auth.GetUser(username)
if user == nil {
return types.UserContext{