本文整理汇总了Golang中github.com/kjk/u.PathExists函数的典型用法代码示例。如果您正苦于以下问题:Golang PathExists函数的具体用法?Golang PathExists怎么用?Golang PathExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PathExists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: genNewArticle
func genNewArticle(title string) {
fmt.Printf("genNewArticle: %q\n", title)
store, err := NewStore()
if err != nil {
log.Fatalf("NewStore() failed with %s", err)
}
newId := findUniqueArticleId(store.articles)
name := sanitizeForFile(title) + ".md"
fmt.Printf("new id: %d, name: %s\n", newId, name)
t := time.Now()
dir := "blog_posts"
d := t.Format("2006-01")
path := filepath.Join(dir, d, name)
s := fmt.Sprintf(`Id: %d
Title: %s
Date: %s
Format: Markdown
--------------`, newId, title, t.Format(time.RFC3339))
for i := 1; i < 10; i++ {
if !u.PathExists(path) {
break
}
name := sanitizeForFile(title) + "-" + strconv.Itoa(i) + ".md"
path = filepath.Join(dir, d, name)
}
u.PanicIf(u.PathExists(path))
fmt.Printf("path: %s\n", path)
u.CreateDirForFileMust(path)
ioutil.WriteFile(path, []byte(s), 0644)
}
示例2: getAppEngineTmplDir
func getAppEngineTmplDir() string {
// when running locally
d := filepath.Join("..", "tmpl")
if u.PathExists(d) {
return d
}
// when running on a server
d = "appengtmpl"
if u.PathExists(d) {
return d
}
logger.Errorf("getAppEngineTmplDir(): %q dir doesn't exist", d)
return ""
}
示例3: getWwwDir
func getWwwDir() string {
// when running locally
d := filepath.Join("..", "www")
if u.PathExists(d) {
return d
}
// when running on a server
d = "www"
if u.PathExists(d) {
return d
}
logger.Errorf("getWwwDir(): %q dir doesn't exist", d)
return ""
}
示例4: serveFileFromDir
func serveFileFromDir(w http.ResponseWriter, r *http.Request, dir, fileName string) {
filePath := filepath.Join(dir, fileName)
if !u.PathExists(filePath) {
logger.Noticef("serveFileFromDir() file %q doesn't exist, referer: %q", fileName, getReferer(r))
}
http.ServeFile(w, r, filePath)
}
示例5: NewStore
func NewStore(dataDir, forumName string) (*Store, error) {
dataFilePath := filepath.Join(dataDir, "forum", forumName+".txt")
store := &Store{
dataDir: dataDir,
forumName: forumName,
posts: make([]*Post, 0),
topics: make([]Topic, 0),
}
var err error
if u.PathExists(dataFilePath) {
if err = store.readExistingData(dataFilePath); err != nil {
fmt.Printf("readExistingData() failed with %s", err)
return nil, err
}
} else {
f, err := os.Create(dataFilePath)
if err != nil {
fmt.Printf("NewStore(): os.Create(%s) failed with %s", dataFilePath, err)
return nil, err
}
f.Close()
}
verifyTopics(store.topics)
store.dataFile, err = os.OpenFile(dataFilePath, os.O_APPEND|os.O_RDWR, 0666)
if err != nil {
fmt.Printf("NewStore(): os.OpenFile(%s) failed with %s", dataFilePath, err)
return nil, err
}
return store, nil
}
示例6: serveFileFromDir
func serveFileFromDir(w http.ResponseWriter, r *http.Request, dir, fileName string) {
filePath := filepath.Join(dir, fileName)
if !u.PathExists(filePath) {
fmt.Printf("serveFileFromDir() file=%s doesn't exist\n", filePath)
}
http.ServeFile(w, r, filePath)
}
示例7: NewStoreCrashes
func NewStoreCrashes(dataDir string) (*StoreCrashes, error) {
dataFilePath := filepath.Join(dataDir, "data", "crashesdata.txt")
store := &StoreCrashes{
dataDir: dataDir,
crashes: make([]*Crash, 0),
apps: make([]*App, 0),
versions: make([]*string, 0),
ips: make(map[string]*string),
crashingLines: make(map[string]*string),
}
var err error
if u.PathExists(dataFilePath) {
err = store.readExistingCrashesData(dataFilePath)
if err != nil {
logger.Errorf("NewStoreCrashes(): readExistingCrashesData() failed with %s\n", err)
return nil, err
}
} else {
f, err := os.Create(dataFilePath)
if err != nil {
logger.Errorf("NewStoreCrashes(): os.Create(%s) failed with %s", dataFilePath, err)
return nil, err
}
f.Close()
}
store.dataFile, err = os.OpenFile(dataFilePath, os.O_APPEND|os.O_RDWR, 0666)
if err != nil {
logger.Errorf("NewStoreCrashes(): os.OpenFile(%s) failed with %s", dataFilePath, err)
return nil, err
}
logger.Noticef("crashes: %d, versions: %d, ips: %d, crashing lines: %d", len(store.crashes), len(store.versions), len(store.ips), len(store.crashingLines))
return store, nil
}
示例8: getDataDir
// 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 ""
}
示例9: handleStatic
// /static/$rest
func handleStatic(w http.ResponseWriter, r *http.Request) {
fileName := r.URL.Path[len("/static/"):]
path := filepath.Join("www", fileName)
if u.PathExists(path) {
LogInfof("%s\n", path)
http.ServeFile(w, r, path)
} else {
LogInfof("file %q doesn't exist, referer: %q\n", path, getReferer(r))
http.NotFound(w, r)
}
}
示例10: readAppData
func readAppData(app *App) error {
var path string
path = app.storeCsvFilePath()
if u.PathExists(path) {
if l, err := store.NewStoreCsv(path); err == nil {
app.store = l
return nil
}
}
return fmt.Errorf("readAppData: %q data file doesn't exist", path)
}
示例11: serveFileFromDir
func serveFileFromDir(w http.ResponseWriter, r *http.Request, dir, fileName string) {
if redirectIfFoundMatching(w, r, dir, fileName) {
return
}
filePath := filepath.Join(dir, fileName)
if u.PathExists(filePath) {
//logger.Noticef("serveFileFromDir(): %q", filePath)
http.ServeFile(w, r, filePath)
} else {
logger.Noticef("serveFileFromDir() file %q doesn't exist, referer: %q", fileName, getReferer(r))
http.NotFound(w, r)
}
}
示例12: removeStoreFiles
func removeStoreFiles(basePath string) {
path := idxFilePath(basePath)
os.Remove(path)
nSegment := 0
for {
path = segmentFilePath(basePath, nSegment)
if !u.PathExists(path) {
break
}
os.Remove(path)
nSegment += 1
}
}
示例13: ensureValidConfig
// tests if s3 credentials are valid and aborts if aren't
func ensureValidConfig(config *BackupConfig) {
if !u.PathExists(config.LocalDir) {
log.Fatalf("Invalid s3 backup: directory to backup %q doesn't exist\n", config.LocalDir)
}
if !strings.HasSuffix(config.S3Dir, bucketDelim) {
config.S3Dir += bucketDelim
}
_, err := listBackupFiles(config, 10)
if err != nil {
log.Fatalf("Invalid s3 backup: bucket.List failed %s\n", err)
}
}
示例14: serveFile
func serveFile(w http.ResponseWriter, r *http.Request, fileName string) {
//LogVerbosef("serverFile: fileName='%s'\n", fileName)
path := filepath.Join("www", fileName)
if hasZipResources() {
serveResourceFromZip(w, r, path)
return
}
if u.PathExists(path) {
http.ServeFile(w, r, path)
} else {
LogVerbosef("file '%s' doesn't exist\n", path)
http.NotFound(w, r)
}
}
示例15: getDataDir
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 ""
}