Ejemplo n.º 1
0
func handler(w http.ResponseWriter, req *http.Request) {
	if *logAccess {
		log.Printf("%s %s %s", req.RemoteAddr, req.Method, req.URL)
	}
	route, hparts := findHandler(req.Method, req.URL.Path)
	defer yellow.DeadlineLog(route.Deadline, "%v:%v deadlined at %v",
		req.Method, req.URL.Path, route.Deadline).Done()

	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Content-type", "application/json")
	route.Handler(hparts, w, req)
}
Ejemplo n.º 2
0
func deadlinedHandler(deadline time.Duration, h http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		q := ""
		if r.URL.RawQuery != "" {
			q = "?" + r.URL.RawQuery
		}

		defer yellow.DeadlineLog(deadline, "%v:%v%v with a deadline of %v",
			r.Method, r.URL.Path, q, deadline).Done()
		h(w, r)
	}
}