nginx-profile-setup/keepalive-svc.go

33 lines
647 B
Go
Raw Normal View History

package main
import (
"fmt"
"net"
"net/http"
"time"
)
type myHandler struct{
nreq int
}
func (h myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Printf("accepted request number %d", h.nreq)
fmt.Fprintf(w, "request number: %d", h.nreq)
}
func main() {
srv := &http.Server{
Addr: ":8080",
Handler: myHandler{nreq: 0},
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 300 * time.Second,
ConnState: func(conn net.Conn, event http.ConnState) {
fmt.Printf("addr: %s, changed state to: %s", conn.RemoteAddr(), event.String())
},
}
srv.ListenAndServe()
}