Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Rewrite shutdown for authorizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kibish committed Feb 24, 2018
1 parent 60f5bfc commit 0d81ec2
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions cmd/authorizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"log"
"net/http"
"os"
"os/signal"
"syscall"

"github.com/skibish/trashdiena/pkg/config"

Expand All @@ -25,22 +27,24 @@ func main() {

sc := slack.New(c.ClientID, c.ClientSecret, c.RedirectURL)
sg := storage.New(fbase)

a := api.New(sc, sg)
go func() {
log.Fatal(a.Start(c.APIPort))
}()

// handle all the gracefull shutdowns
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt)

select {
case <-sigs:
// shutdown gracefully
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
<-sigs
log.Println("Performing shutdown...")
if a != nil {
a.Shutdown()
if err := a.Shutdown(); err != nil {
log.Printf("Failed to shutdown server: %v", err)
}
log.Println("Exiting...")
}()

log.Printf("Authorizer is ready to listen on port: %s", c.APIPort)
if err := a.Start(c.APIPort); err != http.ErrServerClosed {
log.Printf("Server failed: %v", err)
os.Exit(1)
}

log.Println("Exiting...")
}

0 comments on commit 0d81ec2

Please sign in to comment.