當前位置: 首頁>>代碼示例>>Golang>>正文


Golang u.PathExists函數代碼示例

本文整理匯總了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)
}
開發者ID:jedwards36,項目名稱:web-blog,代碼行數:30,代碼來源:main.go

示例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 ""
}
開發者ID:WMAT01,項目名稱:web-blog,代碼行數:14,代碼來源:handler_static.go

示例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 ""
}
開發者ID:WMAT01,項目名稱:web-blog,代碼行數:14,代碼來源:handler_static.go

示例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)
}
開發者ID:leobcn,項目名稱:fofou,代碼行數:7,代碼來源:handlers.go

示例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
}
開發者ID:leobcn,項目名稱:fofou,代碼行數:32,代碼來源:store.go

示例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)
}
開發者ID:leobcn,項目名稱:apptranslator,代碼行數:7,代碼來源:handlers.go

示例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
}
開發者ID:WMAT01,項目名稱:web-blog,代碼行數:35,代碼來源:store_crashes.go

示例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 ""
}
開發者ID:leobcn,項目名稱:apptranslator,代碼行數:19,代碼來源:main.go

示例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)
	}
}
開發者ID:kjk,項目名稱:kjkpub,代碼行數:12,代碼來源:handlers.go

示例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)
}
開發者ID:leobcn,項目名稱:apptranslator,代碼行數:11,代碼來源:main.go

示例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)
	}
}
開發者ID:WMAT01,項目名稱:web-blog,代碼行數:13,代碼來源:handler_static.go

示例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
	}
}
開發者ID:kjk,項目名稱:contentstore,代碼行數:13,代碼來源:store_test.go

示例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)
	}
}
開發者ID:leobcn,項目名稱:fofou,代碼行數:14,代碼來源:s3backup.go

示例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)
	}
}
開發者ID:gophergala2016,項目名稱:kjkteam,代碼行數:14,代碼來源:handlers.go

示例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 ""
}
開發者ID:jedwards36,項目名稱:web-blog,代碼行數:23,代碼來源:main.go


注:本文中的github.com/kjk/u.PathExists函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。