conf for gin engine
This commit is contained in:
parent
5f72059bb6
commit
fb7f88ff7e
3 changed files with 44 additions and 4 deletions
23
main.go
23
main.go
|
|
@ -3,13 +3,16 @@ package main
|
|||
import (
|
||||
"context"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"tg-disc-bot/config"
|
||||
"tg-disc-bot/discordBot"
|
||||
"tg-disc-bot/dto"
|
||||
"tg-disc-bot/router"
|
||||
"tg-disc-bot/tgBot"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -38,13 +41,33 @@ func main() {
|
|||
tgMsgs := tgb.Start(fromDiscord)
|
||||
dsMsgs := dsb.Start(fromTelegram)
|
||||
|
||||
r := router.NewHandler(router.Deps{
|
||||
Addr: net.JoinHostPort(c.HttpConf.Host, c.HttpConf.Port),
|
||||
GinMode: c.HttpConf.GinMode,
|
||||
})
|
||||
|
||||
log.Info("App is now running. Press CTRL-C to exit.")
|
||||
|
||||
errChan := make(chan error, 10)
|
||||
|
||||
go func() {
|
||||
if err = r.Run(); err != nil {
|
||||
errChan <- err
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case sig := <-shutdown:
|
||||
{
|
||||
shutdownCtx, shutdownCancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
|
||||
if err = r.Shutdown(shutdownCtx); err != nil {
|
||||
log.WithError(err).Error("Error shutting down router")
|
||||
}
|
||||
|
||||
log.WithField("type", sig).Info("terminating, close app")
|
||||
shutdownCancel()
|
||||
os.Exit(0)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue