digiadit digiadit - 1 year ago 180
HTTP Question

Golang Http Server Disable Keep-Alive

I trying to disable Keep-Alive Connection in golang but there is no clear explanation about how to do it..

package main

import (

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 :-)")

log.Fatal(http.ListenAndServe(":3030", router))

can anybody solve this?

Answer Source

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}