本文整理匯總了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
}
示例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
}
示例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
}