Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Start https server with defined timeout values
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Nov 8, 2022
1 parent 482ef9d commit 9e728d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 9 additions & 1 deletion healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ func (h *HealthCheck) RunHealthChecks() {
health.AddReadinessCheck("broker-tcp", healthcheck.TCPDialCheck(h.brokerURL, 50*time.Millisecond))

addr := ":" + strconv.Itoa(h.port)
if err := http.ListenAndServe(addr, health); err != nil {
server := &http.Server{
Addr: addr,
Handler: health,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
IdleTimeout: 30 * time.Second,
ReadHeaderTimeout: 3 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}
Expand Down
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"net/http"
"time"

log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -58,13 +59,21 @@ func main() {
hc := NewHealthCheck(8001, config.S3, config.Broker, tlsProxy)
go hc.RunHealthChecks()

server := &http.Server{
Addr: ":8000",
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
IdleTimeout: 30 * time.Second,
ReadHeaderTimeout: 3 * time.Second,
}

if config.Server.cert != "" && config.Server.key != "" {
if e := http.ListenAndServeTLS(":8000", config.Server.cert, config.Server.key, nil); e != nil {
panic(e)
if err := server.ListenAndServeTLS(config.Server.cert, config.Server.key); err != nil {
panic(err)
}
} else {
if e := http.ListenAndServe(":8000", nil); e != nil {
panic(e)
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}
}

0 comments on commit 9e728d3

Please sign in to comment.