-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (38 loc) · 876 Bytes
/
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
package main
import (
"context"
"os"
"os/signal"
"syscall"
"time"
"github.com/hashicorp/go-hclog"
"github.com/resinstack/metaldata/pkg/http"
"github.com/resinstack/metaldata/pkg/source/fs"
)
func main() {
appLogger := hclog.New(&hclog.LoggerOptions{
Name: "metaldata",
Level: hclog.LevelFromString("TRACE"),
})
s := http.New(
http.WithLogger(appLogger),
http.WithInfoSource(fs.New(os.Getenv("MD_FSBASE"))),
)
bind := os.Getenv("MD_BIND")
if bind == "" {
bind = ":3030"
}
go func() {
s.Serve(bind)
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
appLogger.Info("Shutting down...")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := s.Shutdown(ctx); err != nil {
appLogger.Error("Error during shutdown", "error", err)
os.Exit(2)
}
}