From 157d166c512e078676a6a326adb5182be81fd7bb Mon Sep 17 00:00:00 2001 From: Quinn Slack Date: Sat, 19 Jan 2019 22:30:21 -1000 Subject: [PATCH] pass path to VersionedFileSystems for impls that have multiple underlying VFSes --- cmd/docsite/site.go | 6 +++--- fs_test.go | 2 +- handler.go | 4 ++-- site.go | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/docsite/site.go b/cmd/docsite/site.go index 1845280..2c74b7f 100644 --- a/cmd/docsite/site.go +++ b/cmd/docsite/site.go @@ -103,7 +103,7 @@ func openDocsiteFromConfig(configData []byte, baseDir string) (*docsite.Site, *d type nonVersionedFileSystem struct{ http.FileSystem } -func (fs nonVersionedFileSystem) OpenVersion(_ context.Context, version string) (http.FileSystem, error) { +func (fs nonVersionedFileSystem) OpenVersion(_ context.Context, version, path string) (http.FileSystem, error) { if version != "" { return nil, errors.New("content versioning is not supported") } @@ -137,7 +137,7 @@ func openDocsiteFromEnv() (*docsite.Site, *docsiteConfig, error) { content := &versionedFileSystemURL{url: config.Content} // Prefetch content at its default version. This ensures that the program exits if the content // default version is unavailable. - if _, err := content.OpenVersion(context.Background(), ""); err != nil { + if _, err := content.OpenVersion(context.Background(), "", "/"); err != nil { return nil, nil, errors.WithMessage(err, "downloading content default version") } @@ -166,7 +166,7 @@ type fileSystemCacheEntry struct { const fileSystemCacheTTL = 5 * time.Minute -func (fs *versionedFileSystemURL) OpenVersion(ctx context.Context, version string) (http.FileSystem, error) { +func (fs *versionedFileSystemURL) OpenVersion(ctx context.Context, version, path string) (http.FileSystem, error) { // HACK(sqs): this works for codeload.github.com if version == "" { version = "HEAD" diff --git a/fs_test.go b/fs_test.go index de02992..1735496 100644 --- a/fs_test.go +++ b/fs_test.go @@ -42,7 +42,7 @@ func TestWalkFileSystem(t *testing.T) { type versionedFileSystem map[string]http.FileSystem -func (vfs versionedFileSystem) OpenVersion(_ context.Context, version string) (http.FileSystem, error) { +func (vfs versionedFileSystem) OpenVersion(_ context.Context, version, path string) (http.FileSystem, error) { fs, ok := vfs[version] if !ok { return nil, &os.PathError{Op: "OpenVersion", Path: version, Err: os.ErrNotExist} diff --git a/handler.go b/handler.go index 4019a46..288b55a 100644 --- a/handler.go +++ b/handler.go @@ -53,7 +53,7 @@ func (s *Site) Handler() http.Handler { if IsContentAsset(r.URL.Path) { // Serve non-Markdown content files (such as images) using http.FileServer. - content, err := s.Content.OpenVersion(r.Context(), contentVersion) + content, err := s.Content.OpenVersion(r.Context(), contentVersion, r.URL.Path) if err != nil { w.Header().Set("Cache-Control", "max-age=0") if os.IsNotExist(err) { @@ -72,7 +72,7 @@ func (s *Site) Handler() http.Handler { ContentVersion: contentVersion, ContentPagePath: r.URL.Path, } - content, err := s.Content.OpenVersion(r.Context(), contentVersion) + content, err := s.Content.OpenVersion(r.Context(), contentVersion, r.URL.Path) if err != nil { // Version not found. if !os.IsNotExist(err) { diff --git a/site.go b/site.go index e907cad..55eab50 100644 --- a/site.go +++ b/site.go @@ -17,7 +17,7 @@ import ( // VersionedFileSystem represents multiple versions of an http.FileSystem. type VersionedFileSystem interface { - OpenVersion(ctx context.Context, version string) (http.FileSystem, error) + OpenVersion(ctx context.Context, version, path string) (http.FileSystem, error) } // Site represents a documentation site, including all of its templates, assets, and content. @@ -81,7 +81,7 @@ func (s *Site) newContentPage(filePath string, data []byte, contentVersion strin // AllContentPages returns a list of all content pages in the site. func (s *Site) AllContentPages(ctx context.Context, contentVersion string) ([]*ContentPage, error) { - content, err := s.Content.OpenVersion(ctx, contentVersion) + content, err := s.Content.OpenVersion(ctx, contentVersion, "/") if err != nil { return nil, err } @@ -110,7 +110,7 @@ func (s *Site) AllContentPages(ctx context.Context, contentVersion string) ([]*C // If the resulting ContentPage differs from the path argument, the caller should (if possible) // communicate a redirect. func (s *Site) ResolveContentPage(ctx context.Context, contentVersion, path string) (*ContentPage, error) { - content, err := s.Content.OpenVersion(ctx, contentVersion) + content, err := s.Content.OpenVersion(ctx, contentVersion, path) if err != nil { return nil, err }