예제 #1
0
func getFilePath(r *http.Request) string {
	path := r.URL.Path[1:]
	if browser.IsMobile(r) {
		pathsec := strings.SplitN(path, "/", 2)

		if len(pathsec) < 2 {
			return path
		}

		mobpath := "cache/" + pathsec[0] + "/mobile/" + pathsec[1]
		f, err := os.Open(mobpath)
		if err == nil {
			f.Close()
			return mobpath
		}
	} else {
		pathsec := strings.SplitN(path, "/", 2)

		if len(pathsec) < 2 {
			return path
		}

		deskpath := "cache/" + pathsec[0] + "/desktop/" + pathsec[1]
		f, e := os.Open(deskpath)

		if e == nil {
			f.Close()
			return deskpath
		}

	}
	return path
}
예제 #2
0
파일: template.go 프로젝트: WalterShe/wfdr
// Would this template use mobile if it were rendered?
// Changes to a different template for mobile use when:
//  (1) There is such a template in existance AND
//  (2) There is a mobile browser detected (duh).
func WouldUseMobile(r *http.Request) bool {
	return browser.IsMobile(r)
}