Ejemplo n.º 1
0
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"}
}
Ejemplo n.º 2
0
// 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) != ""
}
Ejemplo n.º 3
0
func IsHook(req *wcg.Request) bool {
	return strings.HasPrefix(req.URL().Path, HookPathPrefix)
}
Ejemplo n.º 4
0
func IsStatic(req *wcg.Request) bool {
	return strings.HasPrefix(req.URL().Path, StaticPathPrefix)
}
Ejemplo n.º 5
0
// 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)
}