2024-01-28 07:20:59 +00:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-02-16 13:39:55 +00:00
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
|
2024-01-28 07:20:59 +00:00
|
|
|
router2 "git.lumeweb.com/LumeWeb/portal/api/router"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type API interface {
|
|
|
|
Name() string
|
|
|
|
Init() error
|
|
|
|
Start(ctx context.Context) error
|
|
|
|
Stop(ctx context.Context) error
|
2024-02-16 13:39:55 +00:00
|
|
|
Routes() *httprouter.Router
|
2024-01-28 07:20:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type APIEntry struct {
|
2024-02-16 13:39:55 +00:00
|
|
|
Key string
|
|
|
|
Module fx.Option
|
2024-01-28 07:20:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var apiRegistry []APIEntry
|
|
|
|
var router router2.ProtocolRouter
|
|
|
|
|
2024-01-28 09:44:16 +00:00
|
|
|
func init() {
|
|
|
|
router = make(router2.ProtocolRouter)
|
|
|
|
}
|
|
|
|
|
2024-01-28 07:20:59 +00:00
|
|
|
func Register(entry APIEntry) {
|
|
|
|
apiRegistry = append(apiRegistry, entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetRegistry() []APIEntry {
|
|
|
|
return apiRegistry
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetRouter() router2.ProtocolRouter {
|
|
|
|
return router
|
|
|
|
}
|