diff options
author | Cameron Moore <moorereason@gmail.com> | 2018-09-06 14:21:18 -0500 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-09-07 08:25:51 +0200 |
commit | 5f2e1cb8969c2adac6c866b57cc331e1bc16d4e9 (patch) | |
tree | ca4ceccceed92f9be53d44c889789c902f62fd1e /hugofs/language_fs.go | |
parent | c8ce65046dc7539f3bf5f6dd35fa7ece2bec866d (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/language_fs.go')
-rw-r--r-- | hugofs/language_fs.go | 16 |
1 files changed, 16 insertions, 0 deletions
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 { |