func init() { if internal.InTest() { remoteHost = flag.String("H", "", "Host to run the test against") if internal.InAppEngine() { gaeHost := internal.AppEngineAppHost() if gaeHost == "" { gaeHost = "not found" } gaeRemote = flag.Bool("R", false, fmt.Sprintf("Run tests against remote GAE instance (%s)", gaeHost)) gaeLocal = flag.Bool("L", false, fmt.Sprintf("Run tests local GAE instance (%s)", gaeLocalHost)) } } }
// Relative returns the given path // relative to the application binary // e.g. // binary is at /home/fiam/example/example // Relative("foo") returns /home/fiam/example/foo // Relative("foo/bar") returns /home/fiam/example/foo/bar // Relative("/foo/bar") returns /home/fiam/example/foo/bar. // Note that when running tests (from e.g. go test) or go run // (e.g. go run myfile.go), this function will return the path relative // to the current directory rather than the binary. This is done in // order to allow functions which use relative paths to work under // those circumstances, since go puts the binaries in a temporary // directory when using go test or go run, but runs them from the // current directory. func Relative(name string) string { var full string rel := filepath.FromSlash(name) if internal.InTest() || internal.InAppEngine() || internal.IsGoRun() { cwd, _ := os.Getwd() full = filepath.Join(cwd, rel) } else { if filepath.IsAbs(os.Args[0]) { full = filepath.Join(filepath.Dir(os.Args[0]), rel) } else { full = filepath.Join(iwd, filepath.Dir(os.Args[0]), rel) } } return filepath.Clean(full) }
// Validate performs some basic email address validation on a given // address, just ensuring it's indeed a valid address according to // RFC 5322. If useNetwork is true, the domain will be also validated. // Even if this function returns no error, IT DOESN'T MEAN THE // ADDRESS EXISTS. The only way to be completely sure the address // exist and can receive email is sending an email with a link back // to your site including a randomly generated token that the user // has to click to verify the he can read email sent to that address. // The returned string is the address part of the given string (e.g. // "Alberto G. Hierro <*****@*****.**>" would return // "alberto@garciahierro"). // // Note for GAE: Due to the GAE runtime restrictions, there's no way to // perform DNS lookups, so the useNetwork parameter is ignored when running // on GAE. func Validate(address string, useNetwork bool) (email string, err error) { var addr *mail.Address addr, err = mail.ParseAddress(address) if err != nil { return } if useNetwork && !internal.InAppEngine() { // App Engine does not provide any way to check DNS records. // For now, always return true. TODO: Find a better solution err = validateNetworkAddress(addr.Address) } if err == nil { email = addr.Address } return }
func (app *App) shouldImportAssets() bool { return !app.cfg.TemplateDebug || internal.InAppEngine() }