44 lines
699 B
Go
44 lines
699 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
log "github.com/sirupsen/logrus"
|
|
"parser-mandarake/config"
|
|
"time"
|
|
)
|
|
|
|
const AppName string = "Mandarake parser"
|
|
|
|
type App struct {
|
|
mode string
|
|
}
|
|
|
|
func NewApp(cfg *config.Config) *App {
|
|
a := App{
|
|
mode: cfg.App.Mode,
|
|
}
|
|
|
|
log.Infof("%v: %v", AppName, a.mode)
|
|
return &a
|
|
}
|
|
|
|
func (app *App) Run(ctx context.Context) error {
|
|
log.Info("App started")
|
|
errChan := make(chan error, 3)
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
return app.Shutdown(ctx)
|
|
case err := <-errChan:
|
|
return err
|
|
}
|
|
}
|
|
|
|
func (app *App) Shutdown(ctx context.Context) error {
|
|
log.Info("App shutting down")
|
|
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
|
|
defer cancel()
|
|
|
|
_ = ctx
|
|
return nil
|
|
}
|