forked from tinkerbell/hegel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_server.go
36 lines (29 loc) · 1012 Bytes
/
http_server.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
package main
import (
"fmt"
"net/http"
"github.com/packethost/hegel/xff"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func ServeHTTP(customEndpoints map[string]string) {
mux := &http.ServeMux{}
mux.Handle("/metrics", promhttp.Handler())
mux.HandleFunc("/_packet/healthcheck", healthCheckHandler)
mux.HandleFunc("/_packet/version", versionHandler)
mux.HandleFunc("/2009-04-04", ec2Handler) // workaround for making trailing slash optional
mux.HandleFunc("/2009-04-04/", ec2Handler)
buildSubscriberHandlers(hegelServer)
err := registerCustomEndpoints(mux, customEndpoints)
if err != nil {
logger.Fatal(err, "could not register custom endpoints")
}
trustedProxies := xff.ParseTrustedProxies()
http.Handle("/", xff.HTTPHandler(logger, mux, trustedProxies))
logger.With("port", *metricsPort).Info("Starting http server")
go func() {
err := http.ListenAndServe(fmt.Sprintf(":%d", *metricsPort), nil)
if err != nil {
logger.Fatal(err, "failed to serve http")
}
}()
}