// data dir is ../../data on the server or ~/data/apptranslator locally // the important part is that it's outside of directory with the code func getDataDir() string { if dataDir != "" { return dataDir } // on the server, must be done first because ExpandTildeInPath() // doesn't work when cross-compiled on mac for linux dataDir = filepath.Join("..", "..", "data") if u.PathExists(dataDir) { return dataDir } dataDir = u.ExpandTildeInPath("~/data/apptranslator") if u.PathExists(dataDir) { return dataDir } log.Fatal("data directory (../../data or ../apptranslatordata) doesn't exist") return "" }
func getDataDir() string { if dataDir != "" { return dataDir } // on the server, must be done first because ExpandTildeInPath() // doesn't work when cross-compiled on mac for linux serverDir := filepath.Join("..", "..", "data") dataDir = serverDir if u.PathExists(dataDir) { return dataDir } // locally localDir := u.ExpandTildeInPath("~/data/blog") dataDir = localDir if u.PathExists(dataDir) { return dataDir } log.Fatalf("data directory (%q or %q) doesn't exist", serverDir, localDir) return "" }