Merge pull request #952 from harshavardhana/pr_out_use_values_from_url_object_rather_than_hardcoded_entries
Use values from url object rather than hardcoded entries
This commit is contained in:
@@ -34,18 +34,21 @@ func (s *MySuite) TestURLParse(c *C) {
|
||||
c.Assert(u.Scheme, Equals, "http")
|
||||
c.Assert(u.Host, Equals, "s3.example.com")
|
||||
c.Assert(u.Path, Equals, "/")
|
||||
c.Assert(u.SchemeSeparator, Equals, "://")
|
||||
|
||||
u, err = Parse("http://s3.example.com/path/new")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(u.Scheme, Equals, "http")
|
||||
c.Assert(u.Host, Equals, "s3.example.com")
|
||||
c.Assert(u.Path, Equals, "/path/new")
|
||||
c.Assert(u.SchemeSeparator, Equals, "://")
|
||||
|
||||
u, err = Parse(":::://s3.example.com/path/new")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(u.Scheme, Equals, "")
|
||||
c.Assert(u.Host, Equals, "")
|
||||
c.Assert(u.Path, Equals, ":::://s3.example.com/path/new")
|
||||
c.Assert(u.SchemeSeparator, Equals, "")
|
||||
}
|
||||
|
||||
func (s *MySuite) TestPathParse(c *C) {
|
||||
@@ -54,10 +57,12 @@ func (s *MySuite) TestPathParse(c *C) {
|
||||
c.Assert(u.Scheme, Equals, "")
|
||||
c.Assert(u.Host, Equals, "")
|
||||
c.Assert(u.Path, Equals, "path/test")
|
||||
c.Assert(u.SchemeSeparator, Equals, "")
|
||||
|
||||
u, err = Parse("/path/test")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(u.Scheme, Equals, "")
|
||||
c.Assert(u.Host, Equals, "")
|
||||
c.Assert(u.Path, Equals, "/path/test")
|
||||
c.Assert(u.SchemeSeparator, Equals, "")
|
||||
}
|
||||
|
||||
+3
-3
@@ -65,7 +65,7 @@ func New(config *Config) (client.Client, error) {
|
||||
match, _ := filepath.Match("*.s3*.amazonaws.com", u.Host)
|
||||
if match {
|
||||
hostSplits := strings.SplitN(u.Host, ".", 2)
|
||||
u.Path = "/" + hostSplits[0] + u.Path
|
||||
u.Path = string(u.Separator) + hostSplits[0] + u.Path
|
||||
u.Host = hostSplits[1]
|
||||
}
|
||||
var transport http.RoundTripper
|
||||
@@ -79,13 +79,13 @@ func New(config *Config) (client.Client, error) {
|
||||
AccessKeyID: config.AccessKeyID,
|
||||
SecretAccessKey: config.SecretAccessKey,
|
||||
Transport: transport,
|
||||
Endpoint: u.Scheme + "://" + u.Host,
|
||||
Endpoint: u.Scheme + u.SchemeSeparator + u.Host,
|
||||
}
|
||||
s3Conf.AccessKeyID = config.AccessKeyID
|
||||
s3Conf.SecretAccessKey = config.SecretAccessKey
|
||||
s3Conf.Transport = transport
|
||||
s3Conf.SetUserAgent(config.AppName, config.AppVersion, config.AppComments...)
|
||||
s3Conf.Endpoint = u.Scheme + "://" + u.Host
|
||||
s3Conf.Endpoint = u.Scheme + u.SchemeSeparator + u.Host
|
||||
api, err := minio.New(s3Conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+12
-10
@@ -26,11 +26,12 @@ import (
|
||||
|
||||
// URL client url structure
|
||||
type URL struct {
|
||||
Type URLType
|
||||
Scheme string
|
||||
Host string
|
||||
Path string
|
||||
Separator rune
|
||||
Type URLType
|
||||
Scheme string
|
||||
Host string
|
||||
Path string
|
||||
SchemeSeparator string
|
||||
Separator rune
|
||||
}
|
||||
|
||||
// URLType - enum of different url types
|
||||
@@ -96,11 +97,12 @@ func Parse(urlStr string) (*URL, error) {
|
||||
host := getHost(authority)
|
||||
if host != "" && (scheme == "http" || scheme == "https") {
|
||||
return &URL{
|
||||
Scheme: scheme,
|
||||
Type: Object,
|
||||
Host: host,
|
||||
Path: rest,
|
||||
Separator: '/',
|
||||
Scheme: scheme,
|
||||
Type: Object,
|
||||
Host: host,
|
||||
Path: rest,
|
||||
SchemeSeparator: "://",
|
||||
Separator: '/',
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user