1
0
Fork 0
forked from goffee/cup

migration

This commit is contained in:
Zeni Kim 2024-09-15 19:19:30 -05:00
parent 35d26e5868
commit a756cd418d
6 changed files with 14 additions and 32 deletions

View file

@ -1,18 +0,0 @@
// Copyright 2023 Harran Ali <harran.m@gmail.com>. All rights reserved.
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
// 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()
}

View file

@ -1,4 +1,4 @@
package middlewares package hooks
import ( import (
"errors" "errors"
@ -11,7 +11,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
var AuthCheck core.Middleware = func(c *core.Context) { var AuthCheck core.Hook = func(c *core.Context) {
tokenRaw := c.GetHeader("Authorization") tokenRaw := c.GetHeader("Authorization")
token := strings.TrimSpace(strings.Replace(tokenRaw, "Bearer", "", 1)) token := strings.TrimSpace(strings.Replace(tokenRaw, "Bearer", "", 1))
if token == "" { if token == "" {

View file

@ -3,7 +3,7 @@
// Use of this source code is governed by MIT-style // Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package middlewares package hooks
import ( import (
"fmt" "fmt"
@ -11,8 +11,8 @@ import (
"git.smarteching.com/goffee/core" "git.smarteching.com/goffee/core"
) )
// Example middleware // Example hook
var ExampleMiddleware core.Middleware = func(c *core.Context) { var ExampleHook core.Hook = func(c *core.Context) {
fmt.Println("example middleware!") fmt.Println("example hook!")
c.Next() c.Next()
} }

View file

@ -43,7 +43,7 @@ func main() {
app.SetGormConfig(config.GetGormConfig()) app.SetGormConfig(config.GetGormConfig())
app.SetCacheConfig(config.GetCacheConfig()) app.SetCacheConfig(config.GetCacheConfig())
app.Bootstrap() app.Bootstrap()
registerGlobalMiddlewares() registerGlobalHooks()
registerRoutes() registerRoutes()
registerEvents() registerEvents()
if config.GetGormConfig().EnableGorm == true { if config.GetGormConfig().EnableGorm == true {

View file

@ -5,12 +5,12 @@
package main package main
// Register middlewares globally // Register hooks globally
func registerGlobalMiddlewares() { func registerGlobalHooks() {
//######################################## //########################################
//# Global middlewares registration ##### //# Global hooks registration #####
//######################################## //########################################
// Register global middlewares here ... // Register global hooks here ...
// core.UseMiddleware(middlewares.AnotherExampleMiddleware) // core.UseHook(hooks.AnotherExampleMiddleware)
} }

View file

@ -8,7 +8,7 @@ package main
import ( import (
"git.smarteching.com/goffee/core" "git.smarteching.com/goffee/core"
"git.smarteching.com/goffee/cup/controllers" "git.smarteching.com/goffee/cup/controllers"
"git.smarteching.com/goffee/cup/middlewares" "git.smarteching.com/goffee/cup/hooks"
) )
// Register the app controllers // Register the app controllers
@ -26,5 +26,5 @@ func registerRoutes() {
// controller.Post("/signout", controllers.Signout) // controller.Post("/signout", controllers.Signout)
// controller.Post("/reset-password", controllers.ResetPasswordRequest) // controller.Post("/reset-password", controllers.ResetPasswordRequest)
// controller.Post("/reset-password/code/:code", controllers.SetNewPassword) // controller.Post("/reset-password/code/:code", controllers.SetNewPassword)
controller.Get("/dashboard", controllers.WelcomeToDashboard, middlewares.AuthCheck) controller.Get("/dashboard", controllers.WelcomeToDashboard, hooks.AuthCheck)
} }