本文整理匯總了Golang中github.com/milosgajdos83/servpeek/resource.Filer類的典型用法代碼示例。如果您正苦於以下問題:Golang Filer類的具體用法?Golang Filer怎麽用?Golang Filer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Filer類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ModTimeAfter
// ModTimeAfter checks if the provided file modification time is older than the one passed in as paramter
// It returns error if os.Stat returns error
func ModTimeAfter(f resource.Filer, mtime time.Time) error {
fi, err := f.Info()
if err != nil {
return err
}
if fi.ModTime().After(mtime) {
return nil
}
return fmt.Errorf("%s modification time is bigger than %s", f, mtime)
}
示例2: Size
// Size checks if the provided file byte size is the same as the one passed in as paramter
// It returns error if os.Stat returns error
func Size(f resource.Filer, size int64) error {
fi, err := f.Info()
if err != nil {
return err
}
if fi.Size() == size {
return nil
}
return fmt.Errorf("%s size is different from %d", f, size)
}
示例3: 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)
}
示例4: IsGrupedInto
// IsGrupedInto checks if the provided file is owned by groupname group
// It returns an error if os.Stat returns error
func IsGrupedInto(f resource.Filer, groupname string) error {
fi, err := f.Info()
if err != nil {
return err
}
gid, err := utils.RoleToID("group", groupname)
if err != nil {
return err
}
return isTrueOrError(fi.Sys().(*syscall.Stat_t).Gid == uint32(gid), fmt.Errorf("%s file is not grouped to %s", f, groupname))
}
示例5: IsOwnedBy
// IsOwnedBy checks if the provided file is owned by username user
// It returns an error if os.Stat returns error
func IsOwnedBy(f resource.Filer, username string) error {
fi, err := f.Info()
if err != nil {
return nil
}
uid, err := utils.RoleToID("user", username)
if err != nil {
return err
}
return isTrueOrError(fi.Sys().(*syscall.Stat_t).Uid == uint32(uid), fmt.Errorf("%s file is not owned by %s", f, username))
}
示例6: 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)
})
}
示例7: IsMode
// IsMode checks if the provided file has the same mode as the one passed in via paramter
// It returns error if os.Stat returns error
func IsMode(f resource.Filer, mode os.FileMode) error {
fi, err := f.Info()
if err != nil {
return err
}
if verboseMode, ok := verboseNames[mode]; ok {
err = fmt.Errorf("%s file is not a %s", f, verboseMode)
} else {
err = fmt.Errorf("%s file is not mode %v", f, mode)
}
return isTrueOrError(fi.Mode()&mode != 0, err)
}
示例8: 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)
})
}