I trying to disable Keep-Alive Connection in golang but there is no clear explanation about how to do it..
package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
"fmt"
)
func helloworld(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Hello, World!")
}
func main() {
router := httprouter.New()
router.GET("/", helloworld)
fmt.Println("Running :-)")
http.Server.SetKeepAlivesEnabled(false)
log.Fatal(http.ListenAndServe(":3030", router))
}
can anybody solve this?
SetKeepAlivesEnabled is an instance configuration, not a global one.
If you really need to achieve that, instantiate your own server:
server := &http.Server{Addr: ":3030", Handler: router}
server.SetKeepAlivesEnabled(false)
server.ListenAndServe()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With