package app import ( "log" "git.icedream.tech/icedream/uplink/app/authentication" "git.icedream.tech/icedream/uplink/app/channels" "git.icedream.tech/icedream/uplink/app/servers/http" "git.icedream.tech/icedream/uplink/plugins" ) type registeredPlugin struct { Instance plugins.PluginInstance Descriptor plugins.PluginDescriptor } type App struct { Server *httpserver.Server Authenticator authentication.Authenticator ChannelManager *channels.ChannelManager plugins []registeredPlugin } func New() *App { return &App{ Server: httpserver.NewServer(), Authenticator: new(authentication.DummyAuthenticator), ChannelManager: channels.NewChannelManager(), plugins: []registeredPlugin{}, } } func (app *App) UsePlugin(plugin *plugins.Plugin) { pluginInstance := plugin.Run() if p, ok := pluginInstance.(plugins.ServerPlugin); ok { p.SetServer(app.Server) } if p, ok := pluginInstance.(plugins.ChannelPlugin); ok { p.SetChannelManager(app.ChannelManager) } if p, ok := pluginInstance.(plugins.AuthenticatorPlugin); ok { p.SetAuthenticator(app.Authenticator) } log.Println("Plugin registered:", plugin.Descriptor.Name) app.plugins = append(app.plugins, registeredPlugin{ Instance: pluginInstance, Descriptor: plugin.Descriptor, }) } func (app *App) Init() { for _, plugin := range app.plugins { plugin.Instance.Init() log.Println("Plugin initialized:", plugin.Descriptor.Name) } } func (app *App) Run() error { return app.Server.Run() }