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


Golang AppFileFields.Sha1方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/models.AppFileFields.Sha1方法的典型用法代碼示例。如果您正苦於以下問題:Golang AppFileFields.Sha1方法的具體用法?Golang AppFileFields.Sha1怎麽用?Golang AppFileFields.Sha1使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/cli/cf/models.AppFileFields的用法示例。


在下文中一共展示了AppFileFields.Sha1方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: AppFilesInDir

func AppFilesInDir(dir string) (appFiles []models.AppFileFields, err error) {
	dir, err = filepath.Abs(dir)
	if err != nil {
		return
	}

	err = WalkAppFiles(dir, func(fileName string, fullPath string) (err error) {
		fileInfo, err := os.Lstat(fullPath)
		if err != nil {
			return
		}

		appFile := models.AppFileFields{
			Path: filepath.ToSlash(fileName),
			Size: fileInfo.Size(),
		}

		if fileInfo.IsDir() {
			appFile.Sha1 = "0"
			appFile.Size = 0
		} else {
			hash := sha1.New()
			err = fileutils.CopyPathToWriter(fullPath, hash)
			if err != nil {
				return
			}
			appFile.Sha1 = fmt.Sprintf("%x", hash.Sum(nil))
		}

		appFiles = append(appFiles, appFile)
		return
	})
	return
}
開發者ID:Jack1996,項目名稱:cli,代碼行數:34,代碼來源:app_files.go

示例2: AppFilesInDir

func (appfiles ApplicationFiles) AppFilesInDir(dir string) (appFiles []models.AppFileFields, err error) {
	dir, err = filepath.Abs(dir)
	if err != nil {
		return
	}

	err = appfiles.WalkAppFiles(dir, func(fileName string, fullPath string) error {
		fileInfo, err := os.Lstat(fullPath)
		if err != nil {
			return err
		}

		appFile := models.AppFileFields{
			Path: filepath.ToSlash(fileName),
			Size: fileInfo.Size(),
		}

		if fileInfo.IsDir() {
			appFile.Sha1 = "0"
			appFile.Size = 0
		} else {
			hash := sha1.New()
			file, err := os.Open(fullPath)
			if err != nil {
				return err
			}
			defer file.Close()

			_, err = io.Copy(hash, file)
			if err != nil {
				return err
			}

			appFile.Sha1 = fmt.Sprintf("%x", hash.Sum(nil))
		}

		appFiles = append(appFiles, appFile)

		return nil
	})

	return
}
開發者ID:vframbach,項目名稱:cli,代碼行數:43,代碼來源:app_files.go

示例3: AppFilesInDir

func (appfiles ApplicationFiles) AppFilesInDir(dir string) ([]models.AppFileFields, error) {
	appFiles := []models.AppFileFields{}

	fullDirPath, toplevelErr := filepath.Abs(dir)
	if toplevelErr != nil {
		return appFiles, toplevelErr
	}

	toplevelErr = appfiles.WalkAppFiles(fullDirPath, func(fileName string, fullPath string) error {
		fileInfo, err := os.Lstat(fullPath)
		if err != nil {
			return err
		}

		appFile := models.AppFileFields{
			Path: filepath.ToSlash(fileName),
			Size: fileInfo.Size(),
		}

		if fileInfo.IsDir() {
			appFile.Sha1 = "0"
			appFile.Size = 0
		} else {
			sha, err := appfiles.shaFile(fullPath)
			if err != nil {
				return err
			}
			appFile.Sha1 = sha
		}

		appFiles = append(appFiles, appFile)

		return nil
	})

	return appFiles, toplevelErr
}
開發者ID:Reejoshi,項目名稱:cli,代碼行數:37,代碼來源:app_files.go


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