aboutsummaryrefslogtreecommitdiff
path: root/utils/urls/registry.go
blob: e384a1ee333e66727114b06385ca4beda2b9c358 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package urls

import (
	"sync"

	"dove/utils/collections"

	"github.com/gofiber/fiber/v2"
)

type RegisteredRoute struct {
	Method    HTTPMethod
	Path      string
	Handler   fiber.Handler
	Namespace string
	Name      string
	FullPath  string
}

type RouteRegistry struct {
	Mutex            sync.Mutex
	CurrentNamespace string
	Routes           collections.OrderedMap[string, RegisteredRoute]
}

var registry = &RouteRegistry{
	Routes: collections.OrderedMapOf[string, RegisteredRoute](),
}

func SetNamespace(namespace string) {
	registry.Mutex.Lock()
	defer registry.Mutex.Unlock()
	registry.CurrentNamespace = namespace
}