title: Golang catch sigterm and continue application
body: <p>Is it possible to catch a <code>sigterm</code> in Golang and move on on the code, like a panic/defer?</p>
  
  <p>Example: </p>
  
  <pre><code>func main() {
      fmt.Println("app started")
      setupGracefulShutdown()
  
      for {
      }
      close()    
  }
  
  func close() {
      fmt.Println("infinite loop stopped and got here")
  }
  
  func setupGracefulShutdown() {
      sigChan := make(chan os.Signal)
      signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
  
      go func() {
          fmt.Println(" got interrupt signal: ", &lt;-sigChan)
      }()
  }
  
  // "app started"
  // CTRL + C
  // ^C "got interrupt signal:  interrupt"
  // app don't stop
  </code></pre>
  
  <p>What I want is to print <code>infinite loop stopped and got here</code> and finish application.</p>
  
  <pre><code>// "app started"
  // CTRL + C
  // ^C "got interrupt signal:  interrupt"
  // "infinite loop stopped and got here"
  </code></pre>