From 490c9939b27734ef5da512a0ec916607ec9d974d Mon Sep 17 00:00:00 2001 From: "Anand Babu (AB) Periasamy" Date: Thu, 16 Apr 2015 20:23:41 -0700 Subject: [PATCH] handle URL as a string instead of url.URL --- url-parser.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/url-parser.go b/url-parser.go index 1e146cd2..7096c08b 100644 --- a/url-parser.go +++ b/url-parser.go @@ -73,15 +73,14 @@ func getURLType(urlStr string) urlType { } // url2Object converts URL to bucket and objectname -func url2Object(u *url.URL) (bucketName, objectName string) { - // if url is of scheme file, behave differently by returning - // directory and file instead - switch u.Scheme { - case "c": - fallthrough - case "file": - fallthrough - case "": +func url2Object(urlStr string) (bucketName, objectName string, err error) { + u, err := url.Parse(urlStr) + if err != nil { + return "", "", iodine.New(err, nil) + } + + switch getURLType(urlStr) { + case urlFS: if runtime.GOOS == "windows" { bucketName, objectName = filepath.Split(u.String()) } else { @@ -101,15 +100,19 @@ func url2Object(u *url.URL) (bucketName, objectName string) { objectName = splits[2] } } - return bucketName, objectName + return bucketName, objectName, nil } func newURL(urlStr string) (*parsedURL, error) { + bucketName, objectName, err := url2Object(urlStr) + if err != nil { + return nil, iodine.New(err, nil) + } + u, err := url.Parse(urlStr) if err != nil { return nil, iodine.New(err, nil) } - bucketName, objectName := url2Object(u) parsedURL := &parsedURL{ url: u, scheme: getURLType(urlStr),