Skip to content

Commit

Permalink
Tweak OpenAPI spec embedding (again) (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Aug 1, 2019
1 parent 3661887 commit 5e8ad17
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Expand Up @@ -3,6 +3,7 @@ env:
before:
hooks:
- go mod download
- go generate ./...
project_name: stripe
builds:
- main: ./cmd/stripe/main.go
Expand Down
6 changes: 3 additions & 3 deletions pkg/spec/fs_vfsdata.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/spec/spec.go
@@ -1,4 +1,4 @@
//go:generate go run github.com/shurcooL/vfsgen/cmd/vfsgendev -source="github.com/stripe/stripe-cli/pkg/spec".FS
//go:generate go run vfsgen.go

package spec

Expand Down
68 changes: 68 additions & 0 deletions pkg/spec/vfsgen.go
@@ -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)
}
7 changes: 0 additions & 7 deletions tools/tools.go

This file was deleted.

0 comments on commit 5e8ad17

Please sign in to comment.