本文整理汇总了Golang中github.com/minio/mc/pkg/client/fs.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newClientFromAlias
// newClientFromAlias gives a new client interface for matching
// alias entry in the mc config file. If no matching host config entry
// is found, fs client is returned.
func newClientFromAlias(alias string, urlStr string) (client.Client, *probe.Error) {
hostCfg := mustGetHostConfig(alias)
if hostCfg == nil {
// No matching host config. So we treat it like a
// filesystem.
fsClient, err := fs.New(urlStr)
if err != nil {
return nil, err.Trace(alias, urlStr)
}
return fsClient, nil
}
// We have a valid alias and hostConfig. We populate the
// credentials from the match found in the config file.
s3Config := new(client.Config)
s3Config.AccessKey = hostCfg.AccessKey
s3Config.SecretKey = hostCfg.SecretKey
s3Config.Signature = hostCfg.API
s3Config.AppName = "mc"
s3Config.AppVersion = mcVersion
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
s3Config.HostURL = urlStr
s3Config.Debug = globalDebug
s3Client, err := s3.New(s3Config)
if err != nil {
return nil, err.Trace(alias, urlStr)
}
return s3Client, nil
}
示例2: getNewClient
// getNewClient gives a new client interface
func getNewClient(urlStr string, auth *hostConfig) (clnt client.Client, err error) {
url, err := client.Parse(urlStr)
if err != nil {
return nil, iodine.New(errInvalidURL{URL: urlStr}, map[string]string{"URL": urlStr})
}
switch url.Type {
case client.Object: // Minio and S3 compatible object storage
if auth == nil {
return nil, iodine.New(errInvalidArgument{}, nil)
}
s3Config := new(s3.Config)
s3Config.AccessKeyID = func() string {
if auth.AccessKeyID == globalAccessKeyID {
return ""
}
return auth.AccessKeyID
}()
s3Config.SecretAccessKey = func() string {
if auth.SecretAccessKey == globalSecretAccessKey {
return ""
}
return auth.SecretAccessKey
}()
s3Config.AppName = "Minio"
s3Config.AppVersion = getVersion()
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
s3Config.HostURL = urlStr
s3Config.Debug = globalDebugFlag
return s3.New(s3Config)
case client.Filesystem:
return fs.New(urlStr)
}
return nil, iodine.New(errInvalidURL{URL: urlStr}, nil)
}
示例3: TestPutBucket
func (s *MySuite) TestPutBucket(c *C) {
root, err := ioutil.TempDir(os.TempDir(), "fs-")
c.Assert(err, IsNil)
defer os.RemoveAll(root)
bucketPath := filepath.Join(root, "bucket")
fsc, perr := fs.New(bucketPath)
c.Assert(perr, IsNil)
perr = fsc.MakeBucket()
c.Assert(perr, IsNil)
}
示例4: TestPut
func (s *MySuite) TestPut(c *C) {
root, e := ioutil.TempDir(os.TempDir(), "fs-")
c.Assert(e, IsNil)
defer os.RemoveAll(root)
objectPath := filepath.Join(root, "object")
fsc, err := fs.New(objectPath)
c.Assert(err, IsNil)
data := "hello"
err = fsc.Put(bytes.NewReader([]byte(data)), int64(len(data)), "application/octet-stream")
c.Assert(err, IsNil)
}
示例5: TestPut
func (s *MySuite) TestPut(c *C) {
root, err := ioutil.TempDir(os.TempDir(), "fs-")
c.Assert(err, IsNil)
defer os.RemoveAll(root)
objectPath := filepath.Join(root, "object")
fsc, perr := fs.New(objectPath)
c.Assert(perr, IsNil)
data := "hello"
dataLen := len(data)
perr = fsc.Put(int64(dataLen), bytes.NewReader([]byte(data)))
c.Assert(perr, IsNil)
}
示例6: TestBucketACLFails
func (s *MySuite) TestBucketACLFails(c *C) {
root, err := ioutil.TempDir(os.TempDir(), "fs-")
c.Assert(err, IsNil)
defer os.RemoveAll(root)
bucketPath := filepath.Join(root, "bucket")
fsc, perr := fs.New(bucketPath)
c.Assert(perr, IsNil)
perr = fsc.MakeBucket()
c.Assert(perr, IsNil)
perr = fsc.SetBucketAccess("private")
c.Assert(perr, Not(IsNil))
_, perr = fsc.GetBucketAccess()
c.Assert(perr, Not(IsNil))
}
示例7: getNewClient
// getNewClient gives a new client interface
func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error) {
url := client.NewURL(urlStr)
switch url.Type {
case client.Object: // Minio and S3 compatible cloud storage
s3Config := new(client.Config)
s3Config.AccessKeyID = func() string {
if auth.AccessKeyID == globalAccessKeyID {
return ""
}
return auth.AccessKeyID
}()
s3Config.SecretAccessKey = func() string {
if auth.SecretAccessKey == globalSecretAccessKey {
return ""
}
return auth.SecretAccessKey
}()
s3Config.AppName = "Minio"
s3Config.AppVersion = globalMCVersion
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
s3Config.HostURL = urlStr
s3Config.Debug = globalDebugFlag
var s3Client client.Client
var err *probe.Error
if auth.API == "S3v2" {
s3Client, err = s3v2.New(s3Config)
} else {
s3Client, err = s3v4.New(s3Config)
}
if err != nil {
return nil, err.Trace()
}
return s3Client, nil
case client.Filesystem:
fsClient, err := fs.New(urlStr)
if err != nil {
return nil, err.Trace()
}
return fsClient, nil
}
return nil, errInitClient(urlStr).Trace()
}
示例8: TestGetRange
func (s *MySuite) TestGetRange(c *C) {
root, e := ioutil.TempDir(os.TempDir(), "fs-")
c.Assert(e, IsNil)
defer os.RemoveAll(root)
objectPath := filepath.Join(root, "object")
fsc, err := fs.New(objectPath)
c.Assert(err, IsNil)
data := "hello world"
err = fsc.Put(bytes.NewReader([]byte(data)), int64(len(data)), "application/octet-stream")
c.Assert(err, IsNil)
reader, err := fsc.Get(0, 5)
c.Assert(err, IsNil)
var results bytes.Buffer
_, e = io.Copy(&results, reader)
c.Assert(e, IsNil)
c.Assert([]byte("hello"), DeepEquals, results.Bytes())
}
示例9: TestGetRange
func (s *MySuite) TestGetRange(c *C) {
root, err := ioutil.TempDir(os.TempDir(), "fs-")
c.Assert(err, IsNil)
defer os.RemoveAll(root)
objectPath := filepath.Join(root, "object")
fsc, perr := fs.New(objectPath)
c.Assert(perr, IsNil)
data := "hello world"
dataLen := len(data)
perr = fsc.Put(int64(dataLen), bytes.NewReader([]byte(data)))
c.Assert(perr, IsNil)
reader, size, perr := fsc.Get(0, 5)
c.Assert(perr, IsNil)
var results bytes.Buffer
_, err = io.CopyN(&results, reader, int64(size))
c.Assert(err, IsNil)
c.Assert([]byte("hello"), DeepEquals, results.Bytes())
}
示例10: TestList
func (s *MySuite) TestList(c *C) {
root, err := ioutil.TempDir(os.TempDir(), "fs-")
c.Assert(err, IsNil)
defer os.RemoveAll(root)
objectPath := filepath.Join(root, "object1")
fsc, perr := fs.New(objectPath)
c.Assert(err, IsNil)
data := "hello"
dataLen := len(data)
perr = fsc.Put(int64(dataLen), bytes.NewReader([]byte(data)))
c.Assert(err, IsNil)
objectPath = filepath.Join(root, "object2")
fsc, perr = fs.New(objectPath)
c.Assert(err, IsNil)
perr = fsc.Put(int64(dataLen), bytes.NewReader([]byte(data)))
c.Assert(err, IsNil)
fsc, perr = fs.New(root)
c.Assert(err, IsNil)
var contents []*client.Content
for contentCh := range fsc.List(false, false) {
if contentCh.Err != nil {
perr = contentCh.Err
break
}
contents = append(contents, contentCh.Content)
}
c.Assert(perr, IsNil)
c.Assert(len(contents), Equals, 2)
for _, content := range contents {
c.Assert(content.Type.IsRegular(), Equals, true)
}
objectPath = filepath.Join(root, "test1/newObject1")
fsc, perr = fs.New(objectPath)
c.Assert(err, IsNil)
perr = fsc.Put(int64(dataLen), bytes.NewReader([]byte(data)))
c.Assert(err, IsNil)
fsc, perr = fs.New(root)
c.Assert(err, IsNil)
contents = nil
for contentCh := range fsc.List(false, false) {
if contentCh.Err != nil {
perr = contentCh.Err
break
}
contents = append(contents, contentCh.Content)
}
c.Assert(perr, IsNil)
c.Assert(len(contents), Equals, 3)
for _, content := range contents {
// skip previous regular files
if content.Type.IsRegular() {
continue
}
c.Assert(content.Type.IsDir(), Equals, true)
}
fsc, perr = fs.New(root)
c.Assert(err, IsNil)
contents = nil
for contentCh := range fsc.List(true, false) {
if contentCh.Err != nil {
perr = contentCh.Err
break
}
contents = append(contents, contentCh.Content)
}
c.Assert(err, IsNil)
c.Assert(len(contents), Equals, 5)
var regularFiles int
var regularDirs int
for _, content := range contents {
if content.Type.IsRegular() {
regularFiles++
continue
}
if content.Type.IsDir() {
regularDirs++
continue
}
}
c.Assert(regularDirs, Equals, 2)
c.Assert(regularFiles, Equals, 3)
}
示例11: TestList
func (s *MySuite) TestList(c *C) {
root, e := ioutil.TempDir(os.TempDir(), "fs-")
c.Assert(e, IsNil)
defer os.RemoveAll(root)
objectPath := filepath.Join(root, "object1")
fsc, err := fs.New(objectPath)
c.Assert(err, IsNil)
data := "hello"
err = fsc.Put(bytes.NewReader([]byte(data)), int64(len(data)), "application/octet-stream")
c.Assert(err, IsNil)
objectPath = filepath.Join(root, "object2")
fsc, err = fs.New(objectPath)
c.Assert(err, IsNil)
err = fsc.Put(bytes.NewReader([]byte(data)), int64(len(data)), "application/octet-stream")
c.Assert(err, IsNil)
fsc, err = fs.New(root)
c.Assert(err, IsNil)
var contents []*client.Content
for content := range fsc.List(false, false) {
if content.Err != nil {
err = content.Err
break
}
contents = append(contents, content)
}
c.Assert(err, IsNil)
c.Assert(len(contents), Equals, 1)
c.Assert(contents[0].Type.IsDir(), Equals, true)
objectPath = filepath.Join(root, "test1/newObject1")
fsc, err = fs.New(objectPath)
c.Assert(err, IsNil)
err = fsc.Put(bytes.NewReader([]byte(data)), int64(len(data)), "application/octet-stream")
c.Assert(err, IsNil)
fsc, err = fs.New(root)
c.Assert(err, IsNil)
contents = nil
for content := range fsc.List(false, false) {
if content.Err != nil {
err = content.Err
break
}
contents = append(contents, content)
}
c.Assert(err, IsNil)
c.Assert(len(contents), Equals, 1)
c.Assert(contents[0].Type.IsDir(), Equals, true)
fsc, err = fs.New(root)
c.Assert(err, IsNil)
contents = nil
for content := range fsc.List(true, false) {
if content.Err != nil {
err = content.Err
break
}
contents = append(contents, content)
}
c.Assert(err, IsNil)
c.Assert(len(contents), Equals, 5)
var regularFiles int
var regularDirs int
for _, content := range contents {
if content.Type.IsRegular() {
regularFiles++
continue
}
if content.Type.IsDir() {
regularDirs++
continue
}
}
c.Assert(regularDirs, Equals, 2)
c.Assert(regularFiles, Equals, 3)
}