scaffold/internal/project/local.go

40 lines
702 B
Go
Raw Permalink Normal View History

2020-02-20 08:31:22 +01:00
package project
import (
"net/url"
"strings"
2020-04-07 08:43:59 +02:00
"gopkg.in/src-d/go-billy.v4/osfs"
2020-02-20 08:31:22 +01:00
"gopkg.in/src-d/go-billy.v4"
)
const LocalScheme = "local"
const FileScheme = "file"
type LocalFetcher struct{}
func (f *LocalFetcher) Fetch(url *url.URL) (billy.Filesystem, error) {
2020-04-07 08:43:59 +02:00
return osfs.New(url.Path), nil
2020-02-20 08:31:22 +01:00
}
func (f *LocalFetcher) Match(url *url.URL) bool {
if url.Scheme == LocalScheme || url.Scheme == FileScheme {
return true
}
2020-04-07 08:43:18 +02:00
if url.Scheme == "" && isFilesystemPath(url.Path) {
return true
}
return false
2020-02-20 08:31:22 +01:00
}
func NewLocalFetcher() *LocalFetcher {
return &LocalFetcher{}
}
func isFilesystemPath(path string) bool {
2020-04-07 08:43:18 +02:00
return strings.HasPrefix(path, ".") || strings.HasPrefix(path, "/")
2020-02-20 08:31:22 +01:00
}