41 lines
663 B
Go
41 lines
663 B
Go
package app
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
type App struct {
|
|
worker WorkerInterface
|
|
}
|
|
|
|
func NewApp(worker WorkerInterface) *App {
|
|
return &App{
|
|
worker: worker,
|
|
}
|
|
}
|
|
|
|
func (app *App) Start(while chan struct{}) error {
|
|
go func(while chan struct{}) {
|
|
sigint := make(chan os.Signal, 1)
|
|
signal.Notify(sigint, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
|
<-sigint
|
|
|
|
log.Println("Received signal:", sigint)
|
|
app.Shutdown()
|
|
close(while)
|
|
}(while)
|
|
|
|
return app.worker.Start()
|
|
}
|
|
|
|
func (app *App) Shutdown() {
|
|
app.worker.OnShutdown()
|
|
}
|
|
|
|
func (app *App) RegisterPlugin(plugin Plugin) {
|
|
app.worker.addPlugin(plugin.name, plugin.connect)
|
|
}
|