feat: add dedicated registry for api objects

This commit is contained in:
Derrick Hammer 2024-03-17 08:41:40 -04:00
parent a85ced7c62
commit ae37a186a9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 0 deletions

View File

@ -20,20 +20,34 @@ type APIEntry struct {
} }
var apiEntryRegistry []APIEntry var apiEntryRegistry []APIEntry
var apiRegistry map[string]API
var router *router2.APIRouter var router *router2.APIRouter
func init() { func init() {
router = router2.NewAPIRouter() router = router2.NewAPIRouter()
apiRegistry = make(map[string]API)
} }
func RegisterEntry(entry APIEntry) { func RegisterEntry(entry APIEntry) {
apiEntryRegistry = append(apiEntryRegistry, entry) apiEntryRegistry = append(apiEntryRegistry, entry)
} }
func RegisterAPI(api API) {
apiRegistry[api.Name()] = api
}
func GetEntryRegistry() []APIEntry { func GetEntryRegistry() []APIEntry {
return apiEntryRegistry return apiEntryRegistry
} }
func GetAPI(name string) API {
if _, ok := apiRegistry[name]; !ok {
panic("API not found: " + name)
}
return apiRegistry[name]
}
func GetRouter() *router2.APIRouter { func GetRouter() *router2.APIRouter {
return router return router
} }