go: add server read/write timeouts
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2023-07-19 22:35:42 +02:00
parent 419686eb0c
commit d081a79f6d
Signed by: wanderer
SSH Key Fingerprint: SHA256:MdCZyJ2sHLltrLBp0xQO0O1qTW9BT/xl5nXkDvhlMCI

11
main.go

@ -5,6 +5,7 @@ import (
"io/fs" "io/fs"
"log" "log"
"net/http" "net/http"
"time"
) )
var version = "development" var version = "development"
@ -25,7 +26,15 @@ func main() {
log.Printf("app built from revision '%s'\n", version) log.Printf("app built from revision '%s'\n", version)
log.Print("Listening on :1314...") log.Print("Listening on :1314...")
err = http.ListenAndServe(":1314", nil) // https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
srv := http.Server{
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
Addr: ":1314",
Handler: nil,
}
err = srv.ListenAndServe()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }