go: add server read/write timeouts
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
419686eb0c
commit
d081a79f6d
11
main.go
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user