initial
This commit is contained in:
commit
6a9de539ce
9 changed files with 277 additions and 0 deletions
44
internal/app/handler.go
Normal file
44
internal/app/handler.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue