2018-04-10 14:34:30 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2018-04-10 15:08:40 +00:00
|
|
|
"log"
|
|
|
|
|
2018-04-10 14:34:30 +00:00
|
|
|
"git.icedream.tech/icedream/uplink/app/channels"
|
2018-04-10 15:08:40 +00:00
|
|
|
"git.icedream.tech/icedream/uplink/app/servers/http"
|
|
|
|
"git.icedream.tech/icedream/uplink/plugins"
|
2018-04-10 14:34:30 +00:00
|
|
|
)
|
|
|
|
|
2018-04-10 15:08:40 +00:00
|
|
|
type App struct {
|
|
|
|
Server *httpserver.Server
|
|
|
|
ChannelManager *channels.ChannelManager
|
|
|
|
|
|
|
|
plugins []plugins.PluginInstance
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() *App {
|
|
|
|
return &App{
|
|
|
|
Server: httpserver.NewServer(),
|
|
|
|
ChannelManager: channels.NewChannelManager(),
|
|
|
|
|
|
|
|
plugins: []plugins.PluginInstance{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *App) UsePlugin(plugin *plugins.Plugin) {
|
|
|
|
instance := plugin.Run()
|
|
|
|
app.plugins = append(app.plugins, instance)
|
|
|
|
log.Println("Plugin loaded:", plugin.Descriptor.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *App) Init() {
|
|
|
|
for _, plugin := range app.plugins {
|
|
|
|
if p, ok := plugin.(plugins.ServerPlugin); ok {
|
|
|
|
p.SetServer(app.Server)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *App) Run() error {
|
|
|
|
return app.Server.Run()
|
2018-04-10 14:34:30 +00:00
|
|
|
}
|