本文整理匯總了Golang中github.com/milosgajdos83/servpeek/resource.Filer.Path方法的典型用法代碼示例。如果您正苦於以下問題:Golang Filer.Path方法的具體用法?Golang Filer.Path怎麽用?Golang Filer.Path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/milosgajdos83/servpeek/resource.Filer
的用法示例。
在下文中一共展示了Filer.Path方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LinksTo
// LinksTo checks if the provided file is a symlink which links to path
// It returs error if the link can't be read
func LinksTo(f resource.Filer, path string) error {
dst, err := os.Readlink(path)
if err != nil {
return err
}
if dst == f.Path() {
return nil
}
return fmt.Errorf("%s does not link to %s", f, path)
}
示例2: Sha256
// Sha256 checks if the provided file sha256 checksum is the same as the one passed in as paramter
// It returs error if the provided file can't be open
func Sha256(f resource.Filer, sum string) error {
return withOsFile(f.Path(), func(file *os.File) error {
hasher := sha256.New()
if _, err := io.Copy(hasher, file); err != nil {
return nil
}
if sum == hex.EncodeToString(hasher.Sum(nil)) {
return nil
}
return fmt.Errorf("%s sha256 does not equal to %s", f, sum)
})
}
示例3: Contains
// Contains checks if the provided file content can be matched with any of the regexps
// passed in as paramter. It returs error if the provided file can't be open
func Contains(f resource.Filer, contents ...*regexp.Regexp) error {
return withOsFile(f.Path(), func(file *os.File) error {
scanner := bufio.NewScanner(file)
for scanner.Scan() {
for _, content := range contents {
if content.Match(scanner.Bytes()) {
return nil
}
}
}
return fmt.Errorf("%s does not match any provided regular expression", f)
})
}