Пример #1
0
func TestListenAndServe(t *testing.T) {
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page!"+strconv.Itoa(os.Getpid()))
	})

	var gs ghttp.GraceServer
	gs.ListenerCloseTimeout = 60 * time.Second

	err := gs.ListenAndServe(":6086", mux)
	if err != nil {
		log.Println(err)
	}
}
Пример #2
0
func ExampleServer() {
	var gs ghttp.GraceServer
	gs.ListenerCloseTimeout = 60 * time.Second

	gl, err := ghttp.GetListener(":6086")
	if err != nil {
		log.Println(err)
		return
	}

	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page!"+strconv.Itoa(os.Getpid()))
	})

	err = gs.Serve(gl, nil)
	if err != nil {
		log.Println(err)
	}
}