forked from gepaplexx/multena-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (64 loc) · 1.9 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"crypto/tls"
"fmt"
"net/http"
"runtime"
"github.com/MicahParks/keyfunc/v3"
"github.com/gorilla/mux"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
"github.com/slok/go-http-metrics/middleware"
"github.com/slok/go-http-metrics/middleware/std"
)
type App struct {
Jwks keyfunc.Keyfunc
Cfg *Config
TlS *tls.Config
ServiceAccountToken string
LabelStore Labelstore
i *mux.Router
e *mux.Router
healthy bool
}
var Commit string
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
log.Info().Msg("-------Init Proxy-------")
log.Info().Msgf("Commit: %s", Commit)
log.Debug().Str("go_version", runtime.Version()).Msg("")
log.Debug().Str("go_os", runtime.GOOS).Str("go_arch", runtime.GOARCH).Msg("")
log.Debug().Str("go_compiler", runtime.Compiler).Msg("")
app := App{}
app.WithConfig().
WithSAT().
WithTLSConfig().
WithJWKS().
WithLabelStore().
WithHealthz().
WithRoutes().
StartServer()
log.Info().Any("config", app.Cfg)
log.Info().Msg("------Init Complete------")
select {}
}
// StartServer starts the HTTP server for the proxy and metrics.
func (a *App) StartServer() {
go func() {
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", a.Cfg.Web.Host, a.Cfg.Web.MetricsPort), a.i); err != nil {
log.Fatal().Err(err).Msg("Error while serving metrics")
}
}()
go func() {
mdlw := middleware.New(middleware.Config{
Recorder: metrics.NewRecorder(metrics.Config{}),
Service: "multena",
})
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", a.Cfg.Web.Host, a.Cfg.Web.ProxyPort), std.Handler("/", mdlw, a.e)); err != nil {
log.Fatal().Err(err).Msg("Error while serving proxy")
}
}()
}