func()

in http.go [219:256]


func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	// Parse request.
	if !strings.HasPrefix(r.URL.Path, p.opts.BasePath) {
		panic("HTTPPool serving unexpected path: " + r.URL.Path)
	}
	parts := strings.SplitN(r.URL.Path[len(p.opts.BasePath):], "/", 2)
	if len(parts) != 2 {
		http.Error(w, "bad request", http.StatusBadRequest)
		return
	}
	groupName := parts[0]
	key := parts[1]

	// Fetch the value for this group/key.
	group := GetGroup(groupName)
	if group == nil {
		http.Error(w, "no such group: "+groupName, http.StatusNotFound)
		return
	}
	var ctx Context
	if p.Context != nil {
		ctx = p.Context(r)
	}
	group.Stats.ServerRequests.Add(1)
	switch r.Method {
	case "GET":
		if _, ok := r.URL.Query()["exist"]; ok {
			handleContain(ctx, w, group, key)
			return
		}
		handleGet(ctx, w, group, key)
	case "POST":
		handlePut(ctx, w, group, key, r.Body)
	default:
		http.Error(w, fmt.Sprintf("unsuported method: %s", r.Method), http.StatusBadRequest)
		return
	}
}