summaryrefslogtreecommitdiff
path: root/fs.go
diff options
context:
space:
mode:
Diffstat (limited to 'fs.go')
-rw-r--r--fs.go40
1 files changed, 23 insertions, 17 deletions
diff --git a/fs.go b/fs.go
index 864570b..8358b6a 100644
--- a/fs.go
+++ b/fs.go
@@ -55,25 +55,11 @@ func NewFs(endpoint, bucket, accessKeyID, secretAccessKey string, useSSL bool) (
}
func NewFsFromURL(url string) (*Fs, error) {
- r, err := neturl.ParseRequestURI(url)
+ endpoint, bucket, accessKeyID, secretAccessKey, useSSL, err := parseUrl(url)
if err != nil {
return nil, fmt.Errorf("failed to parse url: %w", err)
}
- useSSL := false
- switch r.Scheme {
- case "http":
- case "https":
- useSSL = true
- default:
- return nil, ErrInvalidProtocol
-
- }
-
- endpoint := r.Host
- bucket := r.Path[1:]
- accessKeyId := r.User.Username()
- secretAccessKey, _ := r.User.Password()
- return NewFs(endpoint, bucket, accessKeyId, secretAccessKey, useSSL)
+ return NewFs(endpoint, bucket, accessKeyID, secretAccessKey, useSSL)
}
// The name of this FileSystem
@@ -286,5 +272,25 @@ func (fs *Fs) readdir(directory string, count int, onlyDir bool) ([]os.FileInfo,
}
func isDirPath(p string) bool {
- return strings.HasSuffix(p, "/")
+ return p == "" || strings.HasSuffix(p, "/")
+}
+
+func parseUrl(url string) (endpoint, bucket, accessKeyID, secretAccessKey string, useSSL bool, err error) {
+ var r *neturl.URL
+ if r, err = neturl.ParseRequestURI(url); err != nil {
+ return
+ }
+ switch r.Scheme {
+ case "http":
+ case "https":
+ useSSL = true
+ default:
+ err = ErrInvalidProtocol
+ return
+ }
+ endpoint = r.Host
+ bucket = r.Path[1:]
+ accessKeyID = r.User.Username()
+ secretAccessKey, _ = r.User.Password()
+ return
}