1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package vfs defines types for abstract file system access and provides an
6 // implementation accessing the file system of the underlying OS.
7 package vfs // import "golang.org/x/tools/godoc/vfs"
15 // RootType indicates the type of files contained within a directory.
17 // It is used to indicate whether a directory is the root
18 // of a GOROOT, a GOPATH, or neither.
19 // An empty string represents the case when a directory is neither.
23 RootTypeGoRoot RootType = "GOROOT"
24 RootTypeGoPath RootType = "GOPATH"
27 // The FileSystem interface specifies the methods godoc is using
28 // to access the file system for which it serves documentation.
29 type FileSystem interface {
31 Lstat(path string) (os.FileInfo, error)
32 Stat(path string) (os.FileInfo, error)
33 ReadDir(path string) ([]os.FileInfo, error)
34 RootType(path string) RootType
38 // Opener is a minimal virtual filesystem that can only open regular files.
39 type Opener interface {
40 Open(name string) (ReadSeekCloser, error)
43 // A ReadSeekCloser can Read, Seek, and Close.
44 type ReadSeekCloser interface {
50 // ReadFile reads the file named by path from fs and returns the contents.
51 func ReadFile(fs Opener, path string) ([]byte, error) {
52 rc, err := fs.Open(path)
57 return ioutil.ReadAll(rc)