-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathmain.go
43 lines (32 loc) · 886 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
package main
import (
"context"
"flag"
"fmt"
"log"
"log/slog"
"net/http"
mon "github.com/antonputra/go-utils/monitoring"
"github.com/prometheus/client_golang/prometheus"
)
func main() {
cp := flag.String("config", "", "path to the config")
flag.Parse()
ctx, done := context.WithCancel(context.Background())
defer done()
cfg := new(Config)
cfg.LoadConfig(*cp)
if cfg.Debug {
slog.SetLogLoggerLevel(slog.LevelDebug)
}
reg := prometheus.NewRegistry()
mon.StartPrometheusServer(cfg.MetricsPort, reg)
s := newServer(ctx, cfg, reg)
mux := http.NewServeMux()
mux.HandleFunc("GET /api/devices", s.getDevices)
mux.HandleFunc("POST /api/devices", s.saveDevice)
mux.HandleFunc("GET /healthz", s.getHealth)
appPort := fmt.Sprintf(":%d", cfg.AppPort)
log.Printf("Starting the web server on port %d", cfg.AppPort)
log.Fatal(http.ListenAndServe(appPort, mux))
}