func main() { http.HandleFunc("/sleep/", func(w http.ResponseWriter, r *http.Request) { duration, err := time.ParseDuration(r.FormValue("duration")) if err != nil { http.Error(w, err.Error(), 400) return } time.Sleep(duration) fmt.Fprintf( w, "started at %s slept for %d nanoseconds from pid %d.\n", time.Now(), duration.Nanoseconds(), os.Getpid(), ) }) log.Println(fmt.Sprintf("Serving :8080 with pid %d.", os.Getpid())) gracehttp.ListenAndServe(":8080", nil) log.Println("Server stoped.") }
func main() { cl := controller.NewController() cl.BeforeAction(beforeAction) cl.AfterAction(afterAction) cl.ExactMatchAction("/exact", exactAction) cl.RegexMatchAction("^/[a-z]+([0-9]+)", regexAction) gracehttp.ListenAndServe(":8001", cl) }
func main() { cl := controller.NewController() cl.AddBeforeAction("^/exact", beforeAction). AddAfterAction("^/([a-z]+)[0-9]+", afterAction). AddExactMatchAction("/exact", exactAction). AddExactMatchAction("/redirect", redirectAction). AddRegexMatchAction("^/[a-z]+([0-9]+)", regexAction). AddDestructFunc("^/([a-z]+)[0-9]+", destruct) gracehttp.ListenAndServe(":8001", cl) }