diff options
| author | Bobby <[email protected]> | 2026-01-15 15:53:17 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-01-15 15:53:17 +0530 |
| commit | c8d0bbb5b54f5cec3ebb245f9a21d8a94b3bd944 (patch) | |
| tree | 6a5c2500da90253ad07a0d5192071bb77f093d36 /utils/urls/path.go | |
| download | cafe-c8d0bbb5b54f5cec3ebb245f9a21d8a94b3bd944.tar.xz cafe-c8d0bbb5b54f5cec3ebb245f9a21d8a94b3bd944.zip | |
Add initial project structure with Go Fiber framework and environment configuration
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..e24ed58 --- /dev/null +++ b/utils/urls/path.go @@ -0,0 +1,51 @@ +package urls + +import ( + "cafe/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 +} |
