feat: add dedicated registry for api objects
This commit is contained in:
parent
a85ced7c62
commit
ae37a186a9
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue