-
Notifications
You must be signed in to change notification settings - Fork 361
/
vfsgen.go
68 lines (57 loc) · 1.41 KB
/
vfsgen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//+build vfsgen
package main
import (
"log"
"net/http"
"os"
"time"
"github.com/shurcooL/vfsgen"
"github.com/stripe/stripe-cli/pkg/spec"
)
func main() {
// Override all file mod times to be the Unix epoch using modTimeFS.
// We do this because vfsgen includes mod times in the output file it
// generates, but mod times are not managed by git. As a result, they can
// be different depending on the developer's machine. Overriding them to a
// fixed value ensures that the generated output will only change when the
// contents of the embedded files change.
var inputFS http.FileSystem = modTimeFS{
fs: spec.FS,
}
err := vfsgen.Generate(inputFS, vfsgen.Options{
PackageName: "spec",
BuildTags: "!dev",
VariableName: "FS",
})
if err != nil {
log.Fatalln(err)
}
}
// modTimeFS is an http.FileSystem wrapper that modifies
// underlying fs such that all of its file mod times are set to the Unix epoch.
type modTimeFS struct {
fs http.FileSystem
}
func (fs modTimeFS) Open(name string) (http.File, error) {
f, err := fs.fs.Open(name)
if err != nil {
return nil, err
}
return modTimeFile{f}, nil
}
type modTimeFile struct {
http.File
}
func (f modTimeFile) Stat() (os.FileInfo, error) {
fi, err := f.File.Stat()
if err != nil {
return nil, err
}
return modTimeFileInfo{fi}, nil
}
type modTimeFileInfo struct {
os.FileInfo
}
func (modTimeFileInfo) ModTime() time.Time {
return time.Unix(0, 0)
}