Skip to content

Commit 6014986

Browse files
committed
Reworked http.ListenAndServe usage
1 parent 2b9dddf commit 6014986

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cmd/internal/gowebhookexec/network.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gowebhookexec
33
import (
44
"log"
55
"net/http"
6+
"time"
67
)
78

89
func Listen(config ViperConfig) {
@@ -12,11 +13,16 @@ func Listen(config ViperConfig) {
1213
http.HandleFunc(handlerConfig.Path, requestHandler.handleRequest)
1314
}
1415

15-
log.Println("Listening on:", config.Host+":"+config.Port)
16+
server := &http.Server{
17+
Addr: config.Host + ":" + config.Port,
18+
ReadHeaderTimeout: 3 * time.Second,
19+
}
20+
21+
log.Println("Listening on:", server.Addr)
1622

1723
if config.SslKey != "" && config.SslCert != "" {
18-
log.Fatal(http.ListenAndServeTLS(config.Host+":"+config.Port, config.SslCert, config.SslKey, nil))
24+
log.Fatal(server.ListenAndServeTLS(config.SslCert, config.SslKey))
1925
} else {
20-
log.Fatal(http.ListenAndServe(config.Host+":"+config.Port, nil))
26+
log.Fatal(server.ListenAndServe())
2127
}
2228
}

0 commit comments

Comments
 (0)