We’ll be back soon!
Sorry for the inconvenience but we’re performing some maintenance at the moment. We’ll be back online shortly!
— The Team
package proxy import ( "html/template" "log" "net/http" "sync" ) // ErrorReporter formats error with a given template // Supports go-style template with {{.ErrMessage}} and {{.ErrCode}} type ErrorReporter struct { Template string Nice bool tmpl struct { *template.Template sync.Once } } // Report formats and sends error to ResponseWriter func (em *ErrorReporter) Report(w http.ResponseWriter, code int) { em.tmpl.Do(func() { if em.Template == "" { em.Template = errDefaultTemplate } tp, err := template.New("errmsg").Parse(em.Template) if err != nil { log.Printf("[WARN] failed to parse error template, %v", err) return } em.tmpl.Template = tp }) if em.tmpl.Template == nil || !em.Nice { http.Error(w, "Server error", code) return } data := struct { ErrMessage string ErrCode int }{ ErrMessage: http.StatusText(code), ErrCode: code, } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("X-Content-Type-Options", "nosniff") w.WriteHeader(code) _ = em.tmpl.Execute(w, &data) } var errDefaultTemplate = `
Sorry for the inconvenience but we’re performing some maintenance at the moment. We’ll be back online shortly!
— The Team