-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (47 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/jasonsoft/log"
"github.com/jasonsoft/napnap"
"github.com/jasonsoft/wakanda/internal/config"
)
func main() {
defer func() {
if r := recover(); r != nil {
// unknown error
err, ok := r.(error)
if !ok {
err = fmt.Errorf("unknown error: %v", err)
}
log.StackTrace().Error(err)
}
}()
config := config.New("app.yml")
initialize(config)
// start http service
nap := napWithMiddlewares(config)
httpEngine := napnap.NewHttpEngine(config.Identity.HTTPBind)
go func() {
log.Info("identity: identity service started")
err := nap.Run(httpEngine)
if err != nil {
log.Error(err)
}
}()
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, syscall.SIGINT, syscall.SIGKILL, syscall.SIGHUP, syscall.SIGTERM)
<-stopChan
log.Info("identity: shutting down server...")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := httpEngine.Shutdown(ctx); err != nil {
log.Errorf("identity: hanlder shutdown error: %v", err)
} else {
log.Info("identity: gracefully stopped")
}
}