chore: parametrize port and prometheus #181
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 46s
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 46s
This commit is contained in:
19
main.go
19
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user