forked from felipemsantana/trumail
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (45 loc) · 1.07 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
56
package main
import (
"net/http"
"os"
"os/signal"
"runtime/pprof"
// "strings"
"syscall"
"time"
"github.com/sirupsen/logrus"
"github.com/envolt/trumail/api"
"github.com/envolt/trumail/config"
)
func main() {
http.DefaultClient = &http.Client{
Timeout: time.Duration(config.HTTPClientTimeout) * time.Second,
}
logger := logrus.New() // New Logger
// if strings.Contains(config.Env, "prod") {
logger.Formatter = new(logrus.JSONFormatter)
// }
l := logger.WithField("port", config.Port)
r, s := api.Initialize(logger)
l.Info("Binding all Trumail endpoints to the router")
api.RegisterEndpoints(r, s)
if config.ServeWeb {
// Set all remaining paths to point to static files (must come after)
r.HandleStatic("./web")
}
handleSignals()
// Listen and Serve
l.Info("Listening and Serving")
r.ListenAndServe(config.Port)
}
func handleSignals() {
sigChan := make(chan os.Signal, 3)
go func() {
for sig := range sigChan {
if sig == syscall.SIGUSR1 {
pprof.Lookup("goroutine").WriteTo(os.Stdout, 2)
}
}
}()
signal.Notify(sigChan, syscall.SIGUSR1)
}