當前位置: 首頁>>代碼示例>>Golang>>正文


Golang client.Config類代碼示例

本文整理匯總了Golang中github.com/minio/mc/pkg/client.Config的典型用法代碼示例。如果您正苦於以下問題:Golang Config類的具體用法?Golang Config怎麽用?Golang Config使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Config類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestObjectOperations

func (s *MySuite) TestObjectOperations(c *C) {
	object := objectHandler(objectHandler{
		resource: "/bucket/object",
		data:     []byte("Hello, World"),
	})
	server := httptest.NewServer(object)
	defer server.Close()

	conf := new(client.Config)
	conf.HostURL = server.URL + object.resource
	s3c, err := New(conf)
	c.Assert(err, IsNil)

	err = s3c.PutObject(int64(len(object.data)), bytes.NewReader(object.data))
	c.Assert(err, IsNil)

	content, err := s3c.Stat()
	c.Assert(err, IsNil)
	c.Assert(content.Name, Equals, "object")
	c.Assert(content.Size, Equals, int64(len(object.data)))
	c.Assert(content.Type.IsRegular(), Equals, true)

	reader, size, err := s3c.GetObject(0, 0)
	c.Assert(size, Equals, int64(len(object.data)))

	var buffer bytes.Buffer
	{
		_, err := io.CopyN(&buffer, reader, int64(size))
		c.Assert(err, IsNil)
		c.Assert(buffer.Bytes(), DeepEquals, object.data)
	}
}
開發者ID:akiradeveloper,項目名稱:mc,代碼行數:32,代碼來源:s3v4_test.go

示例2: 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
}
開發者ID:fwessels,項目名稱:mc,代碼行數:33,代碼來源:common-methods.go

示例3: TestBucketOperations

func (s *MySuite) TestBucketOperations(c *C) {
	bucket := bucketHandler(bucketHandler{
		resource: "/bucket",
	})
	server := httptest.NewServer(bucket)
	defer server.Close()

	conf := new(client.Config)
	conf.HostURL = server.URL + bucket.resource
	s3c, err := New(conf)
	c.Assert(err, IsNil)

	err = s3c.MakeBucket()
	c.Assert(err, IsNil)

	err = s3c.SetBucketAccess("public-read-write")
	c.Assert(err, IsNil)

	conf.HostURL = server.URL + string(s3c.GetURL().Separator)
	s3c, err = New(conf)
	c.Assert(err, IsNil)

	for content := range s3c.List(false, false) {
		c.Assert(content.Err, IsNil)
		c.Assert(content.Type.IsDir(), Equals, true)
	}

	conf.HostURL = server.URL + "/bucket"
	s3c, err = New(conf)
	c.Assert(err, IsNil)

	for content := range s3c.List(false, false) {
		c.Assert(content.Err, IsNil)
		c.Assert(content.Type.IsDir(), Equals, true)
	}

	conf.HostURL = server.URL + "/bucket/"
	s3c, err = New(conf)
	c.Assert(err, IsNil)

	for content := range s3c.List(false, false) {
		c.Assert(content.Err, IsNil)
		c.Assert(content.Type.IsRegular(), Equals, true)
	}
}
開發者ID:fwessels,項目名稱:mc,代碼行數:45,代碼來源:s3_test.go

示例4: 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()
}
開發者ID:akiradeveloper,項目名稱:mc,代碼行數:44,代碼來源:common-methods.go


注:本文中的github.com/minio/mc/pkg/client.Config類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。