Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include/exclude example to docs #68

Open
gmwxio opened this issue Feb 14, 2019 · 2 comments
Open

Add include/exclude example to docs #68

gmwxio opened this issue Feb 14, 2019 · 2 comments

Comments

@gmwxio
Copy link

gmwxio commented Feb 14, 2019

Example

Filters out dot directories and file with no dot (ie linux exec)

not sure if this is the best way of doing this.

// Assets contains project assets.
var vfs_Assets = filterFS{http.Dir(".")}

type filterFS struct {
	fs http.FileSystem
}

func (verFS filterFS) Open(name string) (http.File, error) {
	fmt.Printf("vfs %s\n", name)
	fi, er := verFS.fs.Open(name)
	if er != nil {
		return nil, er
	}
	return filterReaddirFile{fi}, nil
}

type filterReaddirFile struct {
	http.File
}

func (f filterReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
	fis := make([]os.FileInfo, 0)
	fii, err := f.File.Readdir(count)
	if err != nil {
		return nil, err
	}
	for _, fi := range fii {
		if fi.IsDir() && fi.Name()[:1] == "." {
			continue
		}
		if fi.IsDir() || strings.Contains(fi.Name(), ".") {
			fis = append(fis, fi)
		}
	}
	return fis, nil
}
@dmitshur
Copy link
Member

dmitshur commented Feb 14, 2019

Hi, thanks for the suggestion.

not sure if this is the best way of doing this.

That's a reasonable way of doing it.

I've also done this using the github.com/shurcooL/httpfs/filter package. See here for an example.

I will think about it and consider how it can be added to the README. I think there's some re-organization work that needs to happen in order to have a better place to put this kind of general information.

@millergarym
Copy link

Thanks, ok now I get filter.Skip().
You have a preference for functions where I was probably expecting an interface, and therefore found it a bit difficult to parse the api.

An example or two could go a long way.
How about an example http server, where the exec bundles up its own resource. In "dev" mode it uses local fs, in prod it used vfs (pretty standard stuff), and it can lay the resources back on the disk.

git clone git@github.com-wxio:wxio/vfsgen.git
cd vfsgen/example
go build -tags dev
./vfsexample bundle # go.mod so exec is vfsexample not example
go build
mv vfsexample /tmp/
cd /tmp
./vfsexample extract

By the way take a look at https://github.com/wxio/opts - its a replacement for cobra and pflags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants