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

Allow modtime zero value #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Generate(input http.FileSystem, opt Options) error {
}

var toc toc
err = findAndWriteFiles(f, input, &toc)
err = findAndWriteFiles(f, input, &toc, opt.ZeroModTime)
if err != nil {
return err
}
Expand Down Expand Up @@ -87,7 +87,7 @@ type dirInfo struct {
// findAndWriteFiles recursively finds all the file paths in the given directory tree.
// They are added to the given map as keys. Values will be safe function names
// for each file, which will be used when generating the output code.
func findAndWriteFiles(f *os.File, fs http.FileSystem, toc *toc) error {
func findAndWriteFiles(f *os.File, fs http.FileSystem, toc *toc, zm bool) error {
walkFn := func(path string, fi os.FileInfo, r io.ReadSeeker, err error) error {
if err != nil {
log.Printf("can't stat file %q: %v\n", path, err)
Expand Down Expand Up @@ -140,10 +140,15 @@ func findAndWriteFiles(f *os.File, fs http.FileSystem, toc *toc) error {
return err
}

modtime := time.Time{}
if !zm {
modtime = fi.ModTime().UTC()
}

dir := &dirInfo{
Path: path,
Name: pathpkg.Base(path),
ModTime: fi.ModTime().UTC(),
ModTime: modtime,
Entries: entries,
}

Expand Down
3 changes: 3 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type Options struct {
// VariableComment is the comment of the http.FileSystem variable in the generated code.
// If left empty, it defaults to "{{.VariableName}} statically implements the virtual filesystem provided to vfsgen.".
VariableComment string

// Whether or not the modtime of the file should be saved. Default is to save the modtime.
ZeroModTime bool
}

// fillMissing sets default values for mandatory options that are left empty.
Expand Down