本文整理汇总了Golang中github.com/spf13/afero.Fs.Open方法的典型用法代码示例。如果您正苦于以下问题:Golang Fs.Open方法的具体用法?Golang Fs.Open怎么用?Golang Fs.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/afero.Fs
的用法示例。
在下文中一共展示了Fs.Open方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testReaddir
func testReaddir(fs afero.Fs, dir string, contents []string, t *testing.T) {
file, err := fs.Open(dir)
if err != nil {
t.Fatalf("open %q failed: %v", dir, err)
}
defer file.Close()
s, err2 := file.Readdir(-1)
if err2 != nil {
t.Fatalf("readdir %q failed: %v", dir, err2)
}
for _, m := range contents {
found := false
for _, n := range s {
if equal(m, n.Name()) {
if found {
t.Error("present twice:", m)
}
found = true
}
}
if !found {
t.Error("could not find", m)
}
}
}
示例2: NewLazyFileReader
// NewLazyFileReader creates and initializes a new LazyFileReader of filename.
// It checks whether the file can be opened. If it fails, it returns nil and an
// error.
func NewLazyFileReader(fs afero.Fs, filename string) (*LazyFileReader, error) {
f, err := fs.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
return &LazyFileReader{fs: fs, filename: filename, contents: nil, pos: 0}, nil
}
示例3: resGetLocal
// resGetLocal loads the content of a local file
func resGetLocal(url string, fs afero.Fs) ([]byte, error) {
filename := filepath.Join(viper.GetString("WorkingDir"), url)
if e, err := helpers.Exists(filename, fs); !e {
return nil, err
}
f, err := fs.Open(filename)
if err != nil {
return nil, err
}
return ioutil.ReadAll(f)
}
示例4: resGetLocal
// resGetLocal loads the content of a local file
func resGetLocal(url string, fs afero.Fs) ([]byte, error) {
p := ""
if viper.GetString("WorkingDir") != "" {
p = viper.GetString("WorkingDir")
if helpers.FilePathSeparator != p[len(p)-1:] {
p = p + helpers.FilePathSeparator
}
}
jFile := p + url
if e, err := helpers.Exists(jFile, fs); !e {
return nil, err
}
f, err := fs.Open(jFile)
if err != nil {
return nil, err
}
return ioutil.ReadAll(f)
}
示例5: resGetCache
// resGetCache returns the content for an ID from the file cache or an error
// if the file is not found returns nil,nil
func resGetCache(id string, fs afero.Fs, ignoreCache bool) ([]byte, error) {
if ignoreCache {
return nil, nil
}
fID := getCacheFileID(id)
isExists, err := helpers.Exists(fID, fs)
if err != nil {
return nil, err
}
if !isExists {
return nil, nil
}
f, err := fs.Open(fID)
if err != nil {
return nil, err
}
return ioutil.ReadAll(f)
}