implemented os file interface acstraction

This commit is contained in:
ston1th 2022-04-02 14:08:59 +02:00
commit ad41ddbe54
11 changed files with 223 additions and 92 deletions

View 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)
}