GoPLS Viewer

Home|gopls/godoc/vfs/vfs.go
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.
7package vfs // import "golang.org/x/tools/godoc/vfs"
8
9import (
10    "io"
11    "io/ioutil"
12    "os"
13)
14
15// RootType indicates the type of files contained within a directory.
16//
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.
20type RootType string
21
22const (
23    RootTypeGoRoot RootType = "GOROOT"
24    RootTypeGoPath RootType = "GOPATH"
25)
26
27// The FileSystem interface specifies the methods godoc is using
28// to access the file system for which it serves documentation.
29type FileSystem interface {
30    Opener
31    Lstat(path string) (os.FileInfoerror)
32    Stat(path string) (os.FileInfoerror)
33    ReadDir(path string) ([]os.FileInfoerror)
34    RootType(path stringRootType
35    String() string
36}
37
38// Opener is a minimal virtual filesystem that can only open regular files.
39type Opener interface {
40    Open(name string) (ReadSeekClosererror)
41}
42
43// A ReadSeekCloser can Read, Seek, and Close.
44type ReadSeekCloser interface {
45    io.Reader
46    io.Seeker
47    io.Closer
48}
49
50// ReadFile reads the file named by path from fs and returns the contents.
51func ReadFile(fs Openerpath string) ([]byteerror) {
52    rcerr := fs.Open(path)
53    if err != nil {
54        return nilerr
55    }
56    defer rc.Close()
57    return ioutil.ReadAll(rc)
58}
59
MembersX
RootType
RootTypeGoRoot
FileSystem
ReadFile
ReadFile.rc
RootTypeGoPath
Opener
ReadSeekCloser
ReadFile.fs
ReadFile.path
ReadFile.err
Members
X