|
|
@ -0,0 +1,43 @@ |
|
|
|
package minio |
|
|
|
|
|
|
|
import ( |
|
|
|
"net/url" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"github.com/minio/minio-go/v6" |
|
|
|
) |
|
|
|
|
|
|
|
type MinioOption struct { |
|
|
|
Endpoint string |
|
|
|
Access string |
|
|
|
Secret string |
|
|
|
Bucket string |
|
|
|
Secure bool |
|
|
|
} |
|
|
|
|
|
|
|
func ParseURL(s string) (*MinioOption, error) { |
|
|
|
var opt MinioOption |
|
|
|
if u, e := url.Parse(s); nil != e { |
|
|
|
return nil, e //log.Fatalln(e)
|
|
|
|
} else { |
|
|
|
if strings.ToLower(u.Scheme) == "https" { |
|
|
|
opt.Secure = true |
|
|
|
} |
|
|
|
sss := strings.Split(strings.TrimLeft(u.Path, "/"), "/") |
|
|
|
if len(sss) > 0 { |
|
|
|
opt.Bucket = sss[0] |
|
|
|
} |
|
|
|
opt.Endpoint = u.Host |
|
|
|
opt.Access = u.User.Username() |
|
|
|
opt.Secret, _ = u.User.Password() |
|
|
|
} |
|
|
|
return &opt, nil |
|
|
|
} |
|
|
|
|
|
|
|
func New(u string) (*minio.Client, error) { |
|
|
|
if opts, e := ParseURL(u); nil != e { |
|
|
|
return nil, e |
|
|
|
} else { |
|
|
|
return minio.New(opts.Endpoint, opts.Access, opts.Secret, opts.Secure) |
|
|
|
} |
|
|
|
} |