예제 #1
0
파일: app.go 프로젝트: viney/gopkgdoc
func (f handlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {

	if r.Host == "gopkgdoc.appspot.com" {
		p := r.URL.Path
		if strings.HasPrefix(p, "/pkg/") {
			p = p[len("/pkg"):]
		}
		if r.URL.RawQuery != "" {
			p = p + "?" + r.URL.RawQuery
		}
		http.Redirect(w, r, "http://go.pkgdoc.org"+p, 301)
		return
	}

	err := f(w, r)
	if err != nil {
		appengine.NewContext(r).Errorf("Error %s", err.Error())
		if e, ok := err.(doc.GetError); ok {
			http.Error(w, "Error getting files from "+e.Host+".", http.StatusInternalServerError)
		} else if appengine.IsCapabilityDisabled(err) || appengine.IsOverQuota(err) {
			http.Error(w, "Internal error: "+err.Error(), http.StatusInternalServerError)
		} else {
			http.Error(w, "Internal Error", http.StatusInternalServerError)
		}
	}
}
예제 #2
0
파일: app.go 프로젝트: wangmingjob/site
func (f handlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.Host != "www.gorillatoolkit.org" && !appengine.IsDevAppServer() {
		r.URL.Host = "www.gorillatoolkit.org"
		http.Redirect(w, r, r.URL.String(), 301)
		return
	}

	err := f(w, r)
	if err != nil {
		appengine.NewContext(r).Errorf("Error %s", err.Error())
		if e, ok := err.(doc.GetError); ok {
			http.Error(w, "Error getting files from "+e.Host+".", http.StatusInternalServerError)
		} else if appengine.IsCapabilityDisabled(err) || appengine.IsOverQuota(err) {
			http.Error(w, "Internal error: "+err.Error(), http.StatusInternalServerError)
		} else {
			http.Error(w, "Internal Error", http.StatusInternalServerError)
		}
	}
}