This repository was archived by the owner on Nov 27, 2018. It is now read-only.
File tree 1 file changed +17
-13
lines changed
1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ package main
2
2
3
3
import (
4
4
"log"
5
+ "net/http"
5
6
"os"
6
7
"os/signal"
8
+ "syscall"
7
9
8
10
"github.com/skibish/trashdiena/pkg/config"
9
11
@@ -25,22 +27,24 @@ func main() {
25
27
26
28
sc := slack .New (c .ClientID , c .ClientSecret , c .RedirectURL )
27
29
sg := storage .New (fbase )
28
-
29
30
a := api .New (sc , sg )
30
- go func () {
31
- log .Fatal (a .Start (c .APIPort ))
32
- }()
33
-
34
- // handle all the gracefull shutdowns
35
- sigs := make (chan os.Signal , 1 )
36
- signal .Notify (sigs , os .Interrupt )
37
31
38
- select {
39
- case <- sigs :
32
+ // shutdown gracefully
33
+ go func () {
34
+ sigs := make (chan os.Signal , 1 )
35
+ signal .Notify (sigs , os .Interrupt , syscall .SIGTERM )
36
+ <- sigs
40
37
log .Println ("Performing shutdown..." )
41
- if a != nil {
42
- a . Shutdown ( )
38
+ if err := a . Shutdown (); err != nil {
39
+ log . Printf ( "Failed to shutdown server: %v" , err )
43
40
}
44
- log .Println ("Exiting..." )
41
+ }()
42
+
43
+ log .Printf ("Authorizer is ready to listen on port: %s" , c .APIPort )
44
+ if err := a .Start (c .APIPort ); err != http .ErrServerClosed {
45
+ log .Printf ("Server failed: %v" , err )
46
+ os .Exit (1 )
45
47
}
48
+
49
+ log .Println ("Exiting..." )
46
50
}
You can’t perform that action at this time.
0 commit comments