summaryrefslogtreecommitdiffstats
path: root/hugofs
diff options
context:
space:
mode:
authorCameron Moore <moorereason@gmail.com>2018-09-06 14:21:18 -0500
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-09-07 08:25:51 +0200
commit5f2e1cb8969c2adac6c866b57cc331e1bc16d4e9 (patch)
treeca4ceccceed92f9be53d44c889789c902f62fd1e /hugofs
parentc8ce65046dc7539f3bf5f6dd35fa7ece2bec866d (diff)
hugofs: Fix golint issues
Fix godoc issues and the following: hugofs/noop_fs.go:25:2: error var noOpErr should have name of the form errFoo
Diffstat (limited to 'hugofs')
-rw-r--r--hugofs/basepath_real_filename_fs.go11
-rw-r--r--hugofs/language_fs.go16
-rw-r--r--hugofs/noop_fs.go23
-rw-r--r--hugofs/rootmapping_fs.go6
4 files changed, 44 insertions, 12 deletions
diff --git a/hugofs/basepath_real_filename_fs.go b/hugofs/basepath_real_filename_fs.go
index d0c56df74..d419c4ea3 100644
--- a/hugofs/basepath_real_filename_fs.go
+++ b/hugofs/basepath_real_filename_fs.go
@@ -36,16 +36,20 @@ func (f *realFilenameInfo) RealFilename() string {
return f.realFilename
}
+// NewBasePathRealFilenameFs returns a new NewBasePathRealFilenameFs instance
+// using base.
func NewBasePathRealFilenameFs(base *afero.BasePathFs) *BasePathRealFilenameFs {
return &BasePathRealFilenameFs{BasePathFs: base}
}
-// This is a thin wrapper around afero.BasePathFs that provides the real filename
-// in Stat and LstatIfPossible.
+// BasePathRealFilenameFs is a thin wrapper around afero.BasePathFs that
+// provides the real filename in Stat and LstatIfPossible.
type BasePathRealFilenameFs struct {
*afero.BasePathFs
}
+// Stat returns the os.FileInfo structure describing a given file. If there is
+// an error, it will be of type *os.PathError.
func (b *BasePathRealFilenameFs) Stat(name string) (os.FileInfo, error) {
fi, err := b.BasePathFs.Stat(name)
if err != nil {
@@ -64,6 +68,9 @@ func (b *BasePathRealFilenameFs) Stat(name string) (os.FileInfo, error) {
return &realFilenameInfo{FileInfo: fi, realFilename: filename}, nil
}
+// LstatIfPossible returns the os.FileInfo structure describing a given file.
+// It attempts to use Lstat if supported or defers to the os. In addition to
+// the FileInfo, a boolean is returned telling whether Lstat was called.
func (b *BasePathRealFilenameFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
fi, ok, err := b.BasePathFs.LstatIfPossible(name)
diff --git a/hugofs/language_fs.go b/hugofs/language_fs.go
index 45cad8722..ce331fca4 100644
--- a/hugofs/language_fs.go
+++ b/hugofs/language_fs.go
@@ -51,6 +51,7 @@ type FilePather interface {
BaseDir() string
}
+// LanguageDirsMerger implements the afero.DirsMerger interface.
var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
m := make(map[string]*LanguageFileInfo)
@@ -84,6 +85,8 @@ var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
return merged, nil
}
+// LanguageFileInfo is a super-set of os.FileInfo with additional information
+// about the file in relation to its Hugo language.
type LanguageFileInfo struct {
os.FileInfo
lang string
@@ -99,22 +102,27 @@ type LanguageFileInfo struct {
weight int
}
+// Filename returns a file's real filename.
func (fi *LanguageFileInfo) Filename() string {
return fi.realFilename
}
+// Path returns a file's relative filename.
func (fi *LanguageFileInfo) Path() string {
return fi.relFilename
}
+// RealName returns a file's real name.
func (fi *LanguageFileInfo) RealName() string {
return fi.realName
}
+// BaseDir returns a file's base directory.
func (fi *LanguageFileInfo) BaseDir() string {
return fi.baseDir
}
+// Lang returns a file's language.
func (fi *LanguageFileInfo) Lang() string {
return fi.lang
}
@@ -157,6 +165,7 @@ func (l *languageFile) Readdir(c int) (ofi []os.FileInfo, err error) {
return fis, err
}
+// LanguageFs represents a language filesystem.
type LanguageFs struct {
// This Fs is usually created with a BasePathFs
basePath string
@@ -166,6 +175,7 @@ type LanguageFs struct {
afero.Fs
}
+// NewLanguageFs creates a new LanguageFs.
func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *LanguageFs {
if lang == "" {
panic("no lang set for the language fs")
@@ -181,10 +191,12 @@ func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *Languag
return &LanguageFs{lang: lang, languages: languages, basePath: basePath, Fs: fs, nameMarker: marker}
}
+// Lang returns a language filesystem's language.
func (fs *LanguageFs) Lang() string {
return fs.lang
}
+// Stat returns the os.FileInfo of a given file.
func (fs *LanguageFs) Stat(name string) (os.FileInfo, error) {
name, err := fs.realName(name)
if err != nil {
@@ -199,6 +211,7 @@ func (fs *LanguageFs) Stat(name string) (os.FileInfo, error) {
return fs.newLanguageFileInfo(name, fi)
}
+// Open opens the named file for reading.
func (fs *LanguageFs) Open(name string) (afero.File, error) {
name, err := fs.realName(name)
if err != nil {
@@ -212,6 +225,9 @@ func (fs *LanguageFs) Open(name string) (afero.File, error) {
return &languageFile{File: f, fs: fs}, nil
}
+// LstatIfPossible returns the os.FileInfo structure describing a given file.
+// It attempts to use Lstat if supported or defers to the os. In addition to
+// the FileInfo, a boolean is returned telling whether Lstat was called.
func (fs *LanguageFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
name, err := fs.realName(name)
if err != nil {
diff --git a/hugofs/noop_fs.go b/hugofs/noop_fs.go
index 2d06622e4..c3d2f2da5 100644
--- a/hugofs/noop_fs.go
+++ b/hugofs/noop_fs.go
@@ -22,24 +22,27 @@ import (
)
var (
- noOpErr = errors.New("this is a filesystem that does nothing and this operation is not supported")
+ errNoOp = errors.New("this is a filesystem that does nothing and this operation is not supported")
_ afero.Fs = (*noOpFs)(nil)
- NoOpFs = &noOpFs{}
+
+ // NoOpFs provides a no-op filesystem that implements the afero.Fs
+ // interface.
+ NoOpFs = &noOpFs{}
)
type noOpFs struct {
}
func (fs noOpFs) Create(name string) (afero.File, error) {
- return nil, noOpErr
+ return nil, errNoOp
}
func (fs noOpFs) Mkdir(name string, perm os.FileMode) error {
- return noOpErr
+ return errNoOp
}
func (fs noOpFs) MkdirAll(path string, perm os.FileMode) error {
- return noOpErr
+ return errNoOp
}
func (fs noOpFs) Open(name string) (afero.File, error) {
@@ -51,15 +54,15 @@ func (fs noOpFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File,
}
func (fs noOpFs) Remove(name string) error {
- return noOpErr
+ return errNoOp
}
func (fs noOpFs) RemoveAll(path string) error {
- return noOpErr
+ return errNoOp
}
func (fs noOpFs) Rename(oldname string, newname string) error {
- return noOpErr
+ return errNoOp
}
func (fs noOpFs) Stat(name string) (os.FileInfo, error) {
@@ -71,9 +74,9 @@ func (fs noOpFs) Name() string {
}
func (fs noOpFs) Chmod(name string, mode os.FileMode) error {
- return noOpErr
+ return errNoOp
}
func (fs noOpFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
- return noOpErr
+ return errNoOp
}
diff --git a/hugofs/rootmapping_fs.go b/hugofs/rootmapping_fs.go
index 59f49f3a9..176edaa07 100644
--- a/hugofs/rootmapping_fs.go
+++ b/hugofs/rootmapping_fs.go
@@ -94,6 +94,8 @@ func NewRootMappingFs(fs afero.Fs, fromTo ...string) (*RootMappingFs, error) {
rootMapToReal: rootMapToReal.Commit().Root()}, nil
}
+// Stat returns the os.FileInfo structure describing a given file. If there is
+// an error, it will be of type *os.PathError.
func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error) {
if fs.isRoot(name) {
return newRootMappingDirFileInfo(name), nil
@@ -107,6 +109,7 @@ func (fs *RootMappingFs) isRoot(name string) bool {
}
+// Open opens the named file for reading.
func (fs *RootMappingFs) Open(name string) (afero.File, error) {
if fs.isRoot(name) {
return &rootMappingFile{name: name, fs: fs}, nil
@@ -119,6 +122,9 @@ func (fs *RootMappingFs) Open(name string) (afero.File, error) {
return &rootMappingFile{File: f, name: name, fs: fs}, nil
}
+// LstatIfPossible returns the os.FileInfo structure describing a given file.
+// It attempts to use Lstat if supported or defers to the os. In addition to
+// the FileInfo, a boolean is returned telling whether Lstat was called.
func (fs *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
if fs.isRoot(name) {
return newRootMappingDirFileInfo(name), false, nil