Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak OpenAPI spec embedding (again) (#67)
- Loading branch information
Showing
5 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} |
This file was deleted.
Oops, something went wrong.