You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool/ntest/mock/fs.go

43 lines
665 B
Go

package mock
import (
"git.noahlan.cn/noahlan/ntool/ngo"
"io/fs"
"path"
)
// DirEnt create a fs.DirEntry
type DirEnt struct {
Nam string
Dir bool
Typ fs.FileMode
Fi fs.FileInfo
Err error
}
// NewDirEnt create a fs.DirEntry
func NewDirEnt(fpath string, isDir ...bool) *DirEnt {
isd := ngo.FirstOr(isDir, false)
return &DirEnt{Nam: path.Base(fpath), Dir: isd, Typ: fs.ModePerm}
}
// Name get
func (d *DirEnt) Name() string {
return d.Nam
}
// IsDir get
func (d *DirEnt) IsDir() bool {
return d.Dir
}
// Type get
func (d *DirEnt) Type() fs.FileMode {
return d.Typ
}
// Info get
func (d *DirEnt) Info() (fs.FileInfo, error) {
return d.Fi, d.Err
}