chore: parametrize port and prometheus #181
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 46s

This commit is contained in:
2024-10-02 18:27:16 +02:00
parent bddcfc6778
commit 33380e2124
2 changed files with 32 additions and 15 deletions

19
main.go
View File

@@ -48,15 +48,20 @@ func run(ctx context.Context, env func(string) string) {
utils.MustRunMigrations(db, "")
// init servers
prometheusServer := &http.Server{
Addr: ":8081",
Handler: promhttp.Handler(),
var prometheusServer *http.Server
if serverSettings.PrometheusEnabled {
prometheusServer := &http.Server{
Addr: ":8081",
Handler: promhttp.Handler(),
}
go startServer(prometheusServer)
}
httpServer := &http.Server{
Addr: ":8080",
Addr: ":" + serverSettings.Port,
Handler: handler.GetHandler(db, serverSettings),
}
go startServer(prometheusServer)
go startServer(httpServer)
// graceful shutdown
@@ -76,6 +81,10 @@ func startServer(s *http.Server) {
func shutdownServer(s *http.Server, ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
if s == nil {
return
}
<-ctx.Done()
shutdownCtx := context.Background()
shutdownCtx, cancel := context.WithTimeout(shutdownCtx, 10*time.Second)