示例#1
0
文件: io.go 项目: jwiklund/tmpl
func (fsRoot *fsRoot) Writer(path string) (io.Writer, error) {
	realPath := fsRoot.root + string(fsRoot.fs.PathSeparator()) + path
	dir := filepath.Dir(realPath)
	err := vfs.MkdirAll(fsRoot.fs, dir, 0775)
	if err != nil {
		return nil, errors.New("could not create dir " + dir + " due to " + err.Error())
	}
	file, err := fsRoot.fs.OpenFile(realPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0664)
	if err != nil {
		return nil, errors.New("could not open file " + realPath + " due to " + err.Error())
	}
	return file, nil
}
示例#2
0
func fsWithFiles(filenames []string) vfs.Filesystem {
	fs := memfs.Create()
	var err error

	for _, fn := range filenames {

		path := filepath.Dir(fn)
		if path != "" {
			err = vfs.MkdirAll(fs, path, 0700)
			if err != nil {
				panic(err)
			}
		}

		err = touchFile(fs, fn)
		if err != nil {
			panic(err)
		}
	}

	return fs
}