Beispiel #1
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)
	}
}
Beispiel #2
0
func TestServer(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

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

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