implemented os file interface acstraction
This commit is contained in:
parent
23528fe28e
commit
ad41ddbe54
11 changed files with 223 additions and 92 deletions
34
pkg/provider/parse/parse.go
Normal file
34
pkg/provider/parse/parse.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2022 Marius Schellenberger
|
||||
|
||||
package parse
|
||||
|
||||
import (
|
||||
"cachefs/pkg/provider"
|
||||
"cachefs/pkg/provider/mount"
|
||||
"errors"
|
||||
"fmt"
|
||||
neturl "net/url"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrPathNotAbsolute = errors.New("path is not absolute")
|
||||
ErrUnsupportedScheme = errors.New("unsupported scheme")
|
||||
)
|
||||
|
||||
func FS(url string) (provider.FS, error) {
|
||||
u, err := neturl.Parse(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !filepath.IsAbs(u.Path) {
|
||||
return nil, ErrPathNotAbsolute
|
||||
}
|
||||
switch u.Scheme {
|
||||
case "file":
|
||||
return mount.NewFS(u.Path), nil
|
||||
//case "sftp":
|
||||
// return sftp.FS(u.Path), nil
|
||||
}
|
||||
return nil, fmt.Errorf("%w: %s", ErrUnsupportedScheme, u.Scheme)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue