示例#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)
		}
	}
}