Skip to content

Instantly share code, notes, and snippets.

@sunzhongwei
Last active August 29, 2015 14:08
Show Gist options
  • Save sunzhongwei/3b0573d528fdfd6ba1a5 to your computer and use it in GitHub Desktop.
Save sunzhongwei/3b0573d528fdfd6ba1a5 to your computer and use it in GitHub Desktop.
/*
Copyright 2014 Zhongwei Inc.
Author: Zhongwei Sun
EMail: zhongwei.sun2008@gmail.com
$ ab -n 50 -c 5 http://localhost:9000/
*/
package main
import (
"fmt"
"net/http"
"time"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Start at:", time.Now())
time.Sleep(2 * time.Second)
fmt.Fprintf(w, "Hi there, I love %s!\n", r.URL.Path[1:])
fmt.Println("End at:", time.Now())
}
func main() {
port := 9000
fmt.Println("Start server on port:", port)
http.HandleFunc("/", indexHandler)
http.ListenAndServe(fmt.Sprintf(":%v", port), nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment