func (p *Page) handleRoute(i interface{}) { http.HandleFunc(p.site.Root, func(w http.ResponseWriter, r *http.Request) { p.site.base.mutex.Lock() if p.Config.Reload() { p.reset(true) } if p.UrlManage.Manage() { newUrl := p.UrlManage.ReWrite(w, r) if newUrl == "redirect" { p.site.base.mutex.Unlock() return } else { r.URL, _ = url.Parse(newUrl) } } if p.site.supportI18n { if err := p.I18n.Setup(p.Config.DefaultLocalePath, p.Config.DefaultLanguage); err != nil { log.Panic("<Page.handleRoute> ", "I18n(Setup):", err) } } p.setCurrentInfo(r.URL.Path) p.Template = p.CurrentController + p.currentFileName p.site.base.mutex.Unlock() log.Debug("<Page.handleRoute> ", "p.Template:", p.Template) if !p.loadGeneratedHtml(w, r) { p.routeController(i, w, r) } }) }
func Must(t *Template, err error) *Template { if err != nil { log.Panic("<Must> Name: ", t.Name(), ", error:", err) return nil } return t }
func (t *Template) lookup(name string) (tmpl *Template, err error) { tmpl, ok := t.nameSpace.get(name) if !ok { return nil, fmt.Errorf("template: %q is undefined", name) } else { t.nameSpace.mu.RLock() defer t.nameSpace.mu.RUnlock() if tmpl.text.Tree == nil || tmpl.text.Root == nil { return nil, fmt.Errorf("template: %q is an incomplete template", name) } if t.text.Lookup(name) == nil { log.Panic("template internal error: template escaping out of sync") } } return tmpl, err }