github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/godoc/vfs/vfs.go (about) 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. 4 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" 8 9 import ( 10 "io" 11 "io/ioutil" 12 "os" 13 ) 14 15 // The FileSystem interface specifies the methods godoc is using 16 // to access the file system for which it serves documentation. 17 type FileSystem interface { 18 Opener 19 Lstat(path string) (os.FileInfo, error) 20 Stat(path string) (os.FileInfo, error) 21 ReadDir(path string) ([]os.FileInfo, error) 22 String() string 23 } 24 25 // Opener is a minimal virtual filesystem that can only open regular files. 26 type Opener interface { 27 Open(name string) (ReadSeekCloser, error) 28 } 29 30 // A ReadSeekCloser can Read, Seek, and Close. 31 type ReadSeekCloser interface { 32 io.Reader 33 io.Seeker 34 io.Closer 35 } 36 37 // ReadFile reads the file named by path from fs and returns the contents. 38 func ReadFile(fs Opener, path string) ([]byte, error) { 39 rc, err := fs.Open(path) 40 if err != nil { 41 return nil, err 42 } 43 defer rc.Close() 44 return ioutil.ReadAll(rc) 45 }