diff options
| author | Bobby <[email protected]> | 2025-12-19 18:01:24 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-12-19 18:01:24 +0530 |
| commit | b1bfec1ce2987d9fe0cc52e5ae9115977fdf8c24 (patch) | |
| tree | 7080b7dc97522ffe0837a1e0b2965489d7e67664 /utils/urls/path.go | |
| parent | 767297e28d47ee9cf3722054e41caa837f0e68d2 (diff) | |
| download | lain-b1bfec1ce2987d9fe0cc52e5ae9115977fdf8c24.tar.xz lain-b1bfec1ce2987d9fe0cc52e5ae9115977fdf8c24.zip | |
added utils, templates, routes, types, middleware, processors and a whole lot of things for a basic login page
Diffstat (limited to 'utils/urls/path.go')
| -rw-r--r-- | utils/urls/path.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/utils/urls/path.go b/utils/urls/path.go new file mode 100644 index 0000000..e6d4ed7 --- /dev/null +++ b/utils/urls/path.go @@ -0,0 +1,51 @@ +package urls + +import ( + "lain/types" + "strings" + + "github.com/gofiber/fiber/v2" +) + +func Path(method types.HTTPMethod, path string, handler fiber.Handler, name string) { + registry.mutex.Lock() + defer registry.mutex.Unlock() + + namespace := registry.currentNamespace + fullName := name + fullPath := path + + if namespace != "" { + if !strings.HasPrefix(path, "/") { + path = "/" + path + } + + fullName = namespace + "." + name + fullPath = "/" + namespace + path + } else { + if !strings.HasPrefix(fullPath, "/") { + fullPath = "/" + fullPath + } + } + + registry.routes[fullName] = registeredRoute{ + method: method, + path: path, + handler: handler, + namespace: namespace, + name: name, + fullPath: fullPath, + } +} + +func GetFullPath(routeName string) (string, bool) { + registry.mutex.Lock() + defer registry.mutex.Unlock() + + route, ok := registry.routes[routeName] + if !ok { + return "", false + } + + return route.fullPath, true +} |
