From d3b670ed37c567b0cdb68dd8adfaaf20a38c73a2 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sun, 1 Sep 2019 17:54:05 -0400 Subject: [PATCH] but we unleashed a lion --- fs/hdwh/hdwh.go | 34 +++++++++++++++++----------------- fs/hdwh/hdwh_test.go | 2 +- fs/memwh/create.go | 2 +- fs/memwh/http_test.go | 6 +++--- fs/memwh/memwh.go | 26 +++++++++++++------------- fs/memwh/memwh_test.go | 2 +- fs/memwh/mkdirall.go | 2 +- fs/memwh/open.go | 2 +- fs/memwh/stat.go | 2 +- fs/memwh/walk.go | 2 +- 10 files changed, 40 insertions(+), 40 deletions(-) diff --git a/fs/hdwh/hdwh.go b/fs/hdwh/hdwh.go index 3f89b5b..eb9117d 100644 --- a/fs/hdwh/hdwh.go +++ b/fs/hdwh/hdwh.go @@ -12,15 +12,15 @@ import ( "github.com/markbates/pkger/internal/maps" ) -var _ fs.Warehouse = &FS{} +var _ fs.Warehouse = &Warehouse{} -type FS struct { +type Warehouse struct { infos *maps.Infos paths *maps.Paths current here.Info } -func (f *FS) Abs(p string) (string, error) { +func (f *Warehouse) Abs(p string) (string, error) { pt, err := f.Parse(p) if err != nil { return "", err @@ -28,7 +28,7 @@ func (f *FS) Abs(p string) (string, error) { return f.AbsPath(pt) } -func (f *FS) AbsPath(pt fs.Path) (string, error) { +func (f *Warehouse) AbsPath(pt fs.Path) (string, error) { if pt.Pkg == f.current.ImportPath { return filepath.Join(f.current.Dir, pt.Name), nil } @@ -39,12 +39,12 @@ func (f *FS) AbsPath(pt fs.Path) (string, error) { return filepath.Join(info.Dir, pt.Name), nil } -func New() (*FS, error) { +func New() (*Warehouse, error) { info, err := here.Current() if err != nil { return nil, err } - return &FS{ + return &Warehouse{ infos: &maps.Infos{}, paths: &maps.Paths{ Current: info, @@ -53,7 +53,7 @@ func New() (*FS, error) { }, nil } -func (fx *FS) Create(name string) (fs.File, error) { +func (fx *Warehouse) Create(name string) (fs.File, error) { name, err := fx.Abs(name) if err != nil { return nil, err @@ -68,11 +68,11 @@ func (fx *FS) Create(name string) (fs.File, error) { return NewFile(fx, f) } -func (f *FS) Current() (here.Info, error) { +func (f *Warehouse) Current() (here.Info, error) { return f.current, nil } -func (f *FS) Info(p string) (here.Info, error) { +func (f *Warehouse) Info(p string) (here.Info, error) { info, ok := f.infos.Load(p) if ok { return info, nil @@ -86,7 +86,7 @@ func (f *FS) Info(p string) (here.Info, error) { return info, nil } -func (f *FS) MkdirAll(p string, perm os.FileMode) error { +func (f *Warehouse) MkdirAll(p string, perm os.FileMode) error { p, err := f.Abs(p) if err != nil { return err @@ -94,7 +94,7 @@ func (f *FS) MkdirAll(p string, perm os.FileMode) error { return os.MkdirAll(p, perm) } -func (fx *FS) Open(name string) (fs.File, error) { +func (fx *Warehouse) Open(name string) (fs.File, error) { name, err := fx.Abs(name) if err != nil { return nil, err @@ -106,11 +106,11 @@ func (fx *FS) Open(name string) (fs.File, error) { return NewFile(fx, f) } -func (f *FS) Parse(p string) (fs.Path, error) { +func (f *Warehouse) Parse(p string) (fs.Path, error) { return f.paths.Parse(p) } -func (f *FS) ReadFile(s string) ([]byte, error) { +func (f *Warehouse) ReadFile(s string) ([]byte, error) { s, err := f.Abs(s) if err != nil { return nil, err @@ -118,7 +118,7 @@ func (f *FS) ReadFile(s string) ([]byte, error) { return ioutil.ReadFile(s) } -func (f *FS) Stat(name string) (os.FileInfo, error) { +func (f *Warehouse) Stat(name string) (os.FileInfo, error) { pt, err := f.Parse(name) if err != nil { return nil, err @@ -139,7 +139,7 @@ func (f *FS) Stat(name string) (os.FileInfo, error) { return info, nil } -func (f *FS) Walk(p string, wf filepath.WalkFunc) error { +func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error { fp, err := f.Abs(p) if err != nil { return err @@ -165,7 +165,7 @@ func (f *FS) Walk(p string, wf filepath.WalkFunc) error { return err } -func (fx *FS) Remove(name string) error { +func (fx *Warehouse) Remove(name string) error { name, err := fx.Abs(name) if err != nil { return err @@ -173,7 +173,7 @@ func (fx *FS) Remove(name string) error { return os.Remove(name) } -func (fx *FS) RemoveAll(name string) error { +func (fx *Warehouse) RemoveAll(name string) error { name, err := fx.Abs(name) if err != nil { return err diff --git a/fs/hdwh/hdwh_test.go b/fs/hdwh/hdwh_test.go index 488cd36..20d5bb1 100644 --- a/fs/hdwh/hdwh_test.go +++ b/fs/hdwh/hdwh_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" ) -func Test_FS(t *testing.T) { +func Test_Warehouse(t *testing.T) { r := require.New(t) myfs, err := New() diff --git a/fs/memwh/create.go b/fs/memwh/create.go index 6d7a543..e61a835 100644 --- a/fs/memwh/create.go +++ b/fs/memwh/create.go @@ -7,7 +7,7 @@ import ( "github.com/markbates/pkger/fs" ) -func (fx *FS) Create(name string) (fs.File, error) { +func (fx *Warehouse) Create(name string) (fs.File, error) { pt, err := fx.Parse(name) if err != nil { return nil, err diff --git a/fs/memwh/http_test.go b/fs/memwh/http_test.go index 9a9ed14..62fcae3 100644 --- a/fs/memwh/http_test.go +++ b/fs/memwh/http_test.go @@ -3,7 +3,7 @@ package memwh // func Test_HTTP_Dir(t *testing.T) { // r := require.New(t) // -// fs := NewFS() +// fs := NewWarehouse() // // r.NoError(Folder.Create(fs)) // @@ -24,7 +24,7 @@ package memwh // func Test_HTTP_File_Memory(t *testing.T) { // r := require.New(t) // -// fs := NewFS() +// fs := NewWarehouse() // r.NoError(Folder.Create(fs)) // // dir, err := fs.Open("/") @@ -44,7 +44,7 @@ package memwh // func Test_HTTP_Dir_Memory_StripPrefix(t *testing.T) { // r := require.New(t) // -// fs := NewFS() +// fs := NewWarehouse() // r.NoError(Folder.Create(fs)) // // dir, err := fs.Open("/public") diff --git a/fs/memwh/memwh.go b/fs/memwh/memwh.go index a8d9cbb..815adbf 100644 --- a/fs/memwh/memwh.go +++ b/fs/memwh/memwh.go @@ -11,16 +11,16 @@ import ( "github.com/markbates/pkger/internal/maps" ) -var _ fs.Warehouse = &FS{} +var _ fs.Warehouse = &Warehouse{} -func WithInfo(fx *FS, infos ...here.Info) { +func WithInfo(fx *Warehouse, infos ...here.Info) { for _, info := range infos { fx.infos.Store(info.ImportPath, info) } } -func New(info here.Info) (*FS, error) { - f := &FS{ +func New(info here.Info) (*Warehouse, error) { + f := &Warehouse{ infos: &maps.Infos{}, paths: &maps.Paths{ Current: info, @@ -31,14 +31,14 @@ func New(info here.Info) (*FS, error) { return f, nil } -type FS struct { +type Warehouse struct { infos *maps.Infos paths *maps.Paths files *maps.Files current here.Info } -func (f *FS) Abs(p string) (string, error) { +func (f *Warehouse) Abs(p string) (string, error) { pt, err := f.Parse(p) if err != nil { return "", err @@ -46,15 +46,15 @@ func (f *FS) Abs(p string) (string, error) { return f.AbsPath(pt) } -func (f *FS) AbsPath(pt fs.Path) (string, error) { +func (f *Warehouse) AbsPath(pt fs.Path) (string, error) { return pt.String(), nil } -func (f *FS) Current() (here.Info, error) { +func (f *Warehouse) Current() (here.Info, error) { return f.current, nil } -func (f *FS) Info(p string) (here.Info, error) { +func (f *Warehouse) Info(p string) (here.Info, error) { info, ok := f.infos.Load(p) if !ok { return info, fmt.Errorf("no such package %q", p) @@ -63,11 +63,11 @@ func (f *FS) Info(p string) (here.Info, error) { return info, nil } -func (f *FS) Parse(p string) (fs.Path, error) { +func (f *Warehouse) Parse(p string) (fs.Path, error) { return f.paths.Parse(p) } -func (fx *FS) ReadFile(s string) ([]byte, error) { +func (fx *Warehouse) ReadFile(s string) ([]byte, error) { f, err := fx.Open(s) if err != nil { return nil, err @@ -76,7 +76,7 @@ func (fx *FS) ReadFile(s string) ([]byte, error) { return ioutil.ReadAll(f) } -func (fx *FS) Remove(name string) error { +func (fx *Warehouse) Remove(name string) error { pt, err := fx.Parse(name) if err != nil { return err @@ -90,7 +90,7 @@ func (fx *FS) Remove(name string) error { return nil } -func (fx *FS) RemoveAll(name string) error { +func (fx *Warehouse) RemoveAll(name string) error { pt, err := fx.Parse(name) if err != nil { return err diff --git a/fs/memwh/memwh_test.go b/fs/memwh/memwh_test.go index be388e4..1927e2d 100644 --- a/fs/memwh/memwh_test.go +++ b/fs/memwh/memwh_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" ) -func Test_FS(t *testing.T) { +func Test_Warehouse(t *testing.T) { r := require.New(t) info, err := here.Current() diff --git a/fs/memwh/mkdirall.go b/fs/memwh/mkdirall.go index 9694f9b..970917b 100644 --- a/fs/memwh/mkdirall.go +++ b/fs/memwh/mkdirall.go @@ -8,7 +8,7 @@ import ( "github.com/markbates/pkger/fs" ) -func (fx *FS) MkdirAll(p string, perm os.FileMode) error { +func (fx *Warehouse) MkdirAll(p string, perm os.FileMode) error { path, err := fx.Parse(p) if err != nil { return err diff --git a/fs/memwh/open.go b/fs/memwh/open.go index 4304218..671fd43 100644 --- a/fs/memwh/open.go +++ b/fs/memwh/open.go @@ -6,7 +6,7 @@ import ( "github.com/markbates/pkger/fs" ) -func (fx *FS) Open(name string) (fs.File, error) { +func (fx *Warehouse) Open(name string) (fs.File, error) { pt, err := fx.Parse(name) if err != nil { return nil, err diff --git a/fs/memwh/stat.go b/fs/memwh/stat.go index 404095e..af1af38 100644 --- a/fs/memwh/stat.go +++ b/fs/memwh/stat.go @@ -5,7 +5,7 @@ import ( "os" ) -func (fx *FS) Stat(name string) (os.FileInfo, error) { +func (fx *Warehouse) Stat(name string) (os.FileInfo, error) { pt, err := fx.Parse(name) if err != nil { return nil, err diff --git a/fs/memwh/walk.go b/fs/memwh/walk.go index 93d3538..272d4ee 100644 --- a/fs/memwh/walk.go +++ b/fs/memwh/walk.go @@ -8,7 +8,7 @@ import ( "github.com/markbates/pkger/fs" ) -func (f *FS) Walk(p string, wf filepath.WalkFunc) error { +func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error { keys := f.files.Keys() pt, err := f.Parse(p)