minimal app
This commit is contained in:
parent
0c526fd70c
commit
d827debd7f
2 changed files with 51 additions and 1 deletions
23
cmd/main.go
23
cmd/main.go
|
|
@ -1,3 +1,24 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {}
|
import (
|
||||||
|
"context"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"merch-api/config"
|
||||||
|
"merch-api/internal/app"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
cfg := config.NewConfig()
|
||||||
|
|
||||||
|
appl := app.New(cfg)
|
||||||
|
|
||||||
|
if err := appl.Run(ctx); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
29
internal/app/handler.go
Normal file
29
internal/app/handler.go
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"merch-api/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
cfg config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(cfg config.Config) *App {
|
||||||
|
return &App{cfg: cfg}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) Run(ctx context.Context) error {
|
||||||
|
log.Info("Starting application...")
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
app.Shutdown(ctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) Shutdown(ctx context.Context) {
|
||||||
|
log.Info("Shutting down application...")
|
||||||
|
return
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue