func (pi *PageResponse) GetTemplates(req *wcg.Request) []string { if pi.StatusCode >= 400 { file := fmt.Sprintf("%d.html", pi.StatusCode) _, err := os.Stat(path.Join(wcg.ViewConfig.BaseDir, file)) if os.IsNotExist(err) { return []string{"500.html", "header.html", "footer.html"} } return []string{file, "header.html", "footer.html"} } // succses case var _p = pi.templatePath if _p == "" { _p = req.URL().Path } if strings.HasPrefix(_p, "/") { _p = fmt.Sprintf(".%s", _p) // make path (/path/to/endpoint/) relative (./path/to/endpoint) } if path.Ext(_p) == "" { _p = path.Join(_p, "/index.html") } _, err := os.Stat(path.Join(wcg.ViewConfig.BaseDir, _p)) if os.IsNotExist(err) { return []string{"default.html", "header.html", "footer.html"} } return []string{_p, "header.html", "footer.html"} }
// IsCronRequest returns true if the request is comming from cron. func IsCron(req *wcg.Request) bool { return strings.HasPrefix(req.URL().Path, CronPathPrefix) && req.Header(CronHeader) != "" }
func IsHook(req *wcg.Request) bool { return strings.HasPrefix(req.URL().Path, HookPathPrefix) }
func IsStatic(req *wcg.Request) bool { return strings.HasPrefix(req.URL().Path, StaticPathPrefix) }
// IsAPIRequest returns true if the request is comming to an API endpoint. func IsAPI(req *wcg.Request) bool { return strings.HasPrefix(req.URL().Path, APIPathPrefix) }