urfave-cli/flag-gen/assets_generate.go
Ajitem Sahasrabuddhe 2a084945a4
move around code
change package to flag-gen to avoid conflict with flag-generator binary
test code generation
2019-08-04 10:28:08 +05:30

54 lines
1.0 KiB
Go

// +build ignore
package main
import (
"github.com/shurcooL/httpfs/union"
"github.com/shurcooL/vfsgen"
"log"
"net/http"
"os"
"time"
)
// zeroModTimeFileSystem is an http.FileSystem wrapper.
// It exposes a filesystem exactly like Source, except
// all file modification times are changed to zero.
// See https://github.com/shurcooL/vfsgen/pull/40#issuecomment-355416103
type zeroModTimeFileSystem struct {
Source http.FileSystem
}
func (fs zeroModTimeFileSystem) Open(name string) (http.File, error) {
f, err := fs.Source.Open(name)
return file{f}, err
}
type file struct {
http.File
}
func (f file) Stat() (os.FileInfo, error) {
fi, err := f.File.Stat()
return fileInfo{fi}, err
}
type fileInfo struct {
os.FileInfo
}
func (fi fileInfo) ModTime() time.Time { return time.Time{} }
func main() {
err := vfsgen.Generate(zeroModTimeFileSystem{
Source: union.New(map[string]http.FileSystem{
"/templates": http.Dir("templates"),
"/source": http.Dir("source"),
}),
}, vfsgen.Options{})
if err != nil {
log.Fatal(err)
}
}