I
I
irina-stolyarova112021-09-29 12:45:47
go
irina-stolyarova11, 2021-09-29 12:45:47

Which Gracefull shutdown in Golang do you recommend?

Please share a good example of Gracefull shutdown in Golang.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Kulakov, 2021-09-29
@ivankprod

// Graceful shutdown, пишем это перед последней ждущей функцией
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
  <-c
  // здесь логика завершения и очистки ресурсов, например:
  db.Close()
  app.Exit()
}()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question