diff --git a/hooks/another-example-middleware.go.go b/hooks/another-example-middleware.go.go deleted file mode 100644 index 8871f60..0000000 --- a/hooks/another-example-middleware.go.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 Harran Ali . All rights reserved. -// Copyright (c) 2024 Zeni Kim -// Use of this source code is governed by MIT-style -// license that can be found in the LICENSE file. - -package middlewares - -import ( - "fmt" - - "git.smarteching.com/goffee/core" -) - -// Another example middleware -var AnotherExampleMiddleware core.Middleware = func(c *core.Context) { - fmt.Println("another example middleware!") - c.Next() -} diff --git a/hooks/auth-check.go b/hooks/auth-check.go index c2b16c5..f08511e 100644 --- a/hooks/auth-check.go +++ b/hooks/auth-check.go @@ -1,4 +1,4 @@ -package middlewares +package hooks import ( "errors" @@ -11,7 +11,7 @@ import ( "gorm.io/gorm" ) -var AuthCheck core.Middleware = func(c *core.Context) { +var AuthCheck core.Hook = func(c *core.Context) { tokenRaw := c.GetHeader("Authorization") token := strings.TrimSpace(strings.Replace(tokenRaw, "Bearer", "", 1)) if token == "" { diff --git a/hooks/example-middleware.go b/hooks/example-hook.go similarity index 67% rename from hooks/example-middleware.go rename to hooks/example-hook.go index d328b97..258e48d 100644 --- a/hooks/example-middleware.go +++ b/hooks/example-hook.go @@ -3,7 +3,7 @@ // Use of this source code is governed by MIT-style // license that can be found in the LICENSE file. -package middlewares +package hooks import ( "fmt" @@ -11,8 +11,8 @@ import ( "git.smarteching.com/goffee/core" ) -// Example middleware -var ExampleMiddleware core.Middleware = func(c *core.Context) { - fmt.Println("example middleware!") +// Example hook +var ExampleHook core.Hook = func(c *core.Context) { + fmt.Println("example hook!") c.Next() } diff --git a/main.go b/main.go index 2d83130..cc02e00 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,7 @@ func main() { app.SetGormConfig(config.GetGormConfig()) app.SetCacheConfig(config.GetCacheConfig()) app.Bootstrap() - registerGlobalMiddlewares() + registerGlobalHooks() registerRoutes() registerEvents() if config.GetGormConfig().EnableGorm == true { diff --git a/register-global-middlewares.go b/register-global-hooks.go similarity index 61% rename from register-global-middlewares.go rename to register-global-hooks.go index 6460798..357d000 100644 --- a/register-global-middlewares.go +++ b/register-global-hooks.go @@ -5,12 +5,12 @@ package main -// Register middlewares globally -func registerGlobalMiddlewares() { +// Register hooks globally +func registerGlobalHooks() { //######################################## - //# Global middlewares registration ##### + //# Global hooks registration ##### //######################################## - // Register global middlewares here ... - // core.UseMiddleware(middlewares.AnotherExampleMiddleware) + // Register global hooks here ... + // core.UseHook(hooks.AnotherExampleMiddleware) } diff --git a/routes.go b/routes.go index e2df92d..c32a746 100644 --- a/routes.go +++ b/routes.go @@ -8,7 +8,7 @@ package main import ( "git.smarteching.com/goffee/core" "git.smarteching.com/goffee/cup/controllers" - "git.smarteching.com/goffee/cup/middlewares" + "git.smarteching.com/goffee/cup/hooks" ) // Register the app controllers @@ -26,5 +26,5 @@ func registerRoutes() { // controller.Post("/signout", controllers.Signout) // controller.Post("/reset-password", controllers.ResetPasswordRequest) // controller.Post("/reset-password/code/:code", controllers.SetNewPassword) - controller.Get("/dashboard", controllers.WelcomeToDashboard, middlewares.AuthCheck) + controller.Get("/dashboard", controllers.WelcomeToDashboard, hooks.AuthCheck) }