mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
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
This commit is contained in:
parent
c8ce65046d
commit
5f2e1cb896
4 changed files with 44 additions and 12 deletions
|
@ -36,16 +36,20 @@ func (f *realFilenameInfo) RealFilename() string {
|
||||||
return f.realFilename
|
return f.realFilename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewBasePathRealFilenameFs returns a new NewBasePathRealFilenameFs instance
|
||||||
|
// using base.
|
||||||
func NewBasePathRealFilenameFs(base *afero.BasePathFs) *BasePathRealFilenameFs {
|
func NewBasePathRealFilenameFs(base *afero.BasePathFs) *BasePathRealFilenameFs {
|
||||||
return &BasePathRealFilenameFs{BasePathFs: base}
|
return &BasePathRealFilenameFs{BasePathFs: base}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a thin wrapper around afero.BasePathFs that provides the real filename
|
// BasePathRealFilenameFs is a thin wrapper around afero.BasePathFs that
|
||||||
// in Stat and LstatIfPossible.
|
// provides the real filename in Stat and LstatIfPossible.
|
||||||
type BasePathRealFilenameFs struct {
|
type BasePathRealFilenameFs struct {
|
||||||
*afero.BasePathFs
|
*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) {
|
func (b *BasePathRealFilenameFs) Stat(name string) (os.FileInfo, error) {
|
||||||
fi, err := b.BasePathFs.Stat(name)
|
fi, err := b.BasePathFs.Stat(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -64,6 +68,9 @@ func (b *BasePathRealFilenameFs) Stat(name string) (os.FileInfo, error) {
|
||||||
return &realFilenameInfo{FileInfo: fi, realFilename: filename}, nil
|
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) {
|
func (b *BasePathRealFilenameFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
|
||||||
|
|
||||||
fi, ok, err := b.BasePathFs.LstatIfPossible(name)
|
fi, ok, err := b.BasePathFs.LstatIfPossible(name)
|
||||||
|
|
|
@ -51,6 +51,7 @@ type FilePather interface {
|
||||||
BaseDir() string
|
BaseDir() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LanguageDirsMerger implements the afero.DirsMerger interface.
|
||||||
var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
|
var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
|
||||||
m := make(map[string]*LanguageFileInfo)
|
m := make(map[string]*LanguageFileInfo)
|
||||||
|
|
||||||
|
@ -84,6 +85,8 @@ var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
|
||||||
return merged, nil
|
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 {
|
type LanguageFileInfo struct {
|
||||||
os.FileInfo
|
os.FileInfo
|
||||||
lang string
|
lang string
|
||||||
|
@ -99,22 +102,27 @@ type LanguageFileInfo struct {
|
||||||
weight int
|
weight int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filename returns a file's real filename.
|
||||||
func (fi *LanguageFileInfo) Filename() string {
|
func (fi *LanguageFileInfo) Filename() string {
|
||||||
return fi.realFilename
|
return fi.realFilename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Path returns a file's relative filename.
|
||||||
func (fi *LanguageFileInfo) Path() string {
|
func (fi *LanguageFileInfo) Path() string {
|
||||||
return fi.relFilename
|
return fi.relFilename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RealName returns a file's real name.
|
||||||
func (fi *LanguageFileInfo) RealName() string {
|
func (fi *LanguageFileInfo) RealName() string {
|
||||||
return fi.realName
|
return fi.realName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BaseDir returns a file's base directory.
|
||||||
func (fi *LanguageFileInfo) BaseDir() string {
|
func (fi *LanguageFileInfo) BaseDir() string {
|
||||||
return fi.baseDir
|
return fi.baseDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lang returns a file's language.
|
||||||
func (fi *LanguageFileInfo) Lang() string {
|
func (fi *LanguageFileInfo) Lang() string {
|
||||||
return fi.lang
|
return fi.lang
|
||||||
}
|
}
|
||||||
|
@ -157,6 +165,7 @@ func (l *languageFile) Readdir(c int) (ofi []os.FileInfo, err error) {
|
||||||
return fis, err
|
return fis, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LanguageFs represents a language filesystem.
|
||||||
type LanguageFs struct {
|
type LanguageFs struct {
|
||||||
// This Fs is usually created with a BasePathFs
|
// This Fs is usually created with a BasePathFs
|
||||||
basePath string
|
basePath string
|
||||||
|
@ -166,6 +175,7 @@ type LanguageFs struct {
|
||||||
afero.Fs
|
afero.Fs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewLanguageFs creates a new LanguageFs.
|
||||||
func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *LanguageFs {
|
func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *LanguageFs {
|
||||||
if lang == "" {
|
if lang == "" {
|
||||||
panic("no lang set for the language fs")
|
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}
|
return &LanguageFs{lang: lang, languages: languages, basePath: basePath, Fs: fs, nameMarker: marker}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lang returns a language filesystem's language.
|
||||||
func (fs *LanguageFs) Lang() string {
|
func (fs *LanguageFs) Lang() string {
|
||||||
return fs.lang
|
return fs.lang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stat returns the os.FileInfo of a given file.
|
||||||
func (fs *LanguageFs) Stat(name string) (os.FileInfo, error) {
|
func (fs *LanguageFs) Stat(name string) (os.FileInfo, error) {
|
||||||
name, err := fs.realName(name)
|
name, err := fs.realName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -199,6 +211,7 @@ func (fs *LanguageFs) Stat(name string) (os.FileInfo, error) {
|
||||||
return fs.newLanguageFileInfo(name, fi)
|
return fs.newLanguageFileInfo(name, fi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open opens the named file for reading.
|
||||||
func (fs *LanguageFs) Open(name string) (afero.File, error) {
|
func (fs *LanguageFs) Open(name string) (afero.File, error) {
|
||||||
name, err := fs.realName(name)
|
name, err := fs.realName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -212,6 +225,9 @@ func (fs *LanguageFs) Open(name string) (afero.File, error) {
|
||||||
return &languageFile{File: f, fs: fs}, nil
|
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) {
|
func (fs *LanguageFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
|
||||||
name, err := fs.realName(name)
|
name, err := fs.realName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -22,24 +22,27 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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)
|
_ afero.Fs = (*noOpFs)(nil)
|
||||||
NoOpFs = &noOpFs{}
|
|
||||||
|
// NoOpFs provides a no-op filesystem that implements the afero.Fs
|
||||||
|
// interface.
|
||||||
|
NoOpFs = &noOpFs{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type noOpFs struct {
|
type noOpFs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs noOpFs) Create(name string) (afero.File, error) {
|
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 {
|
func (fs noOpFs) Mkdir(name string, perm os.FileMode) error {
|
||||||
return noOpErr
|
return errNoOp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs noOpFs) MkdirAll(path string, perm os.FileMode) error {
|
func (fs noOpFs) MkdirAll(path string, perm os.FileMode) error {
|
||||||
return noOpErr
|
return errNoOp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs noOpFs) Open(name string) (afero.File, error) {
|
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 {
|
func (fs noOpFs) Remove(name string) error {
|
||||||
return noOpErr
|
return errNoOp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs noOpFs) RemoveAll(path string) error {
|
func (fs noOpFs) RemoveAll(path string) error {
|
||||||
return noOpErr
|
return errNoOp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs noOpFs) Rename(oldname string, newname string) error {
|
func (fs noOpFs) Rename(oldname string, newname string) error {
|
||||||
return noOpErr
|
return errNoOp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs noOpFs) Stat(name string) (os.FileInfo, error) {
|
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 {
|
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 {
|
func (fs noOpFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||||
return noOpErr
|
return errNoOp
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,8 @@ func NewRootMappingFs(fs afero.Fs, fromTo ...string) (*RootMappingFs, error) {
|
||||||
rootMapToReal: rootMapToReal.Commit().Root()}, nil
|
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) {
|
func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error) {
|
||||||
if fs.isRoot(name) {
|
if fs.isRoot(name) {
|
||||||
return newRootMappingDirFileInfo(name), nil
|
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) {
|
func (fs *RootMappingFs) Open(name string) (afero.File, error) {
|
||||||
if fs.isRoot(name) {
|
if fs.isRoot(name) {
|
||||||
return &rootMappingFile{name: name, fs: fs}, nil
|
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
|
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) {
|
func (fs *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
|
||||||
if fs.isRoot(name) {
|
if fs.isRoot(name) {
|
||||||
return newRootMappingDirFileInfo(name), false, nil
|
return newRootMappingDirFileInfo(name), false, nil
|
||||||
|
|
Loading…
Reference in a new issue