当前位置: 首页>>代码示例>>Golang>>正文


Golang s3.New函数代码示例

本文整理汇总了Golang中github.com/ks3sdklib/aws-sdk-go/service/s3.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestUploadFailCleanup

func TestUploadFailCleanup(t *testing.T) {
	svc := s3.New(nil)

	// Break checksum on 2nd part so it fails
	part := 0
	svc.Handlers.Build.PushBack(func(r *aws.Request) {
		if r.Operation.Name == "UploadPart" {
			if part == 1 {
				r.HTTPRequest.Header.Set("X-Amz-Content-Sha256", "000")
			}
			part++
		}
	})

	key := "12mb-leave"
	mgr := s3manager.NewUploader(&s3manager.UploadOptions{
		S3:                svc,
		LeavePartsOnError: false,
	})
	_, err := mgr.Upload(&s3manager.UploadInput{
		Bucket: bucketName,
		Key:    &key,
		Body:   bytes.NewReader(integBuf12MB),
	})
	assert.Error(t, err)
	uploadID := ""
	if merr, ok := err.(s3manager.MultiUploadFailure); ok {
		uploadID = merr.UploadID()
	}
	assert.NotEmpty(t, uploadID)

	_, err = svc.ListParts(&s3.ListPartsInput{
		Bucket: bucketName, Key: &key, UploadID: &uploadID})
	assert.Error(t, err)
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:35,代码来源:integration_test.go

示例2: dlLoggingSvc

func dlLoggingSvc(data []byte) (*s3.S3, *[]string, *[]string) {
	var m sync.Mutex
	names := []string{}
	ranges := []string{}

	svc := s3.New(nil)
	svc.Handlers.Send.Clear()
	svc.Handlers.Send.PushBack(func(r *aws.Request) {
		m.Lock()
		defer m.Unlock()

		names = append(names, r.Operation.Name)
		ranges = append(ranges, *r.Params.(*s3.GetObjectInput).Range)

		rerng := regexp.MustCompile(`bytes=(\d+)-(\d+)`)
		rng := rerng.FindStringSubmatch(r.HTTPRequest.Header.Get("Range"))
		start, _ := strconv.ParseInt(rng[1], 10, 64)
		fin, _ := strconv.ParseInt(rng[2], 10, 64)
		fin++

		if fin > int64(len(data)) {
			fin = int64(len(data))
		}

		r.HTTPResponse = &http.Response{
			StatusCode: 200,
			Body:       ioutil.NopCloser(bytes.NewReader(data[start:fin])),
			Header:     http.Header{},
		}
		r.HTTPResponse.Header.Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d",
			start, fin, len(data)))
	})

	return svc, &names, &ranges
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:35,代码来源:download_test.go

示例3: main

func main() {
	credentials := credentials.NewStaticCredentials("lMQTr0hNlMpB0iOk/i+x", "D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I", "")
	svc := s3.New(&aws.Config{
		Region:           "HANGZHOU",
		Credentials:      credentials,
		Endpoint:         "kss.ksyun.com",
		DisableSSL:       true,
		LogLevel:         1,
		S3ForcePathStyle: true,
		LogHTTPBody:      true,
	})
	//listBuckets(svc)
	//putBucket(svc)
	//headBucket(svc)
	//deleteBucket(svc)
	//getBucketAcl(svc)
	//listObjects(svc)
	//getBucketLogging(svc)
	//putBucketAcl(svc)
	//putBucketLogging(svc)
	//getBucketLocation(svc)
	//deleteObject(svc)

	//headObject(svc)
	//putObject(svc)
	//getObjectPresignedUrl(svc)
	//getObject(svc)
	//getObjectAcl(svc)
	//multipart(svc)
	deleteObjects(svc)

	//getObjectPresignedUrl(svc)
	//copyObject(svc)
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:34,代码来源:test.go

示例4: loggingSvc

func loggingSvc() (*s3.S3, *[]string, *[]interface{}) {
	var m sync.Mutex
	partNum := 0
	names := []string{}
	params := []interface{}{}
	svc := s3.New(nil)
	svc.Handlers.Unmarshal.Clear()
	svc.Handlers.UnmarshalMeta.Clear()
	svc.Handlers.UnmarshalError.Clear()
	svc.Handlers.Send.Clear()
	svc.Handlers.Send.PushBack(func(r *aws.Request) {
		m.Lock()
		defer m.Unlock()

		names = append(names, r.Operation.Name)
		params = append(params, r.Params)

		r.HTTPResponse = &http.Response{
			StatusCode: 200,
			Body:       ioutil.NopCloser(bytes.NewReader([]byte{})),
		}

		switch data := r.Data.(type) {
		case *s3.CreateMultipartUploadOutput:
			data.UploadID = aws.String("UPLOAD-ID")
		case *s3.UploadPartOutput:
			partNum++
			data.ETag = aws.String(fmt.Sprintf("ETAG%d", partNum))
		case *s3.CompleteMultipartUploadOutput:
			data.Location = aws.String("https://location")
		}
	})

	return svc, &names, &params
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:35,代码来源:upload_test.go

示例5: TestMD5InPutBucketPolicy

func TestMD5InPutBucketPolicy(t *testing.T) {
	svc := s3.New(nil)
	req, _ := svc.PutBucketPolicyRequest(&s3.PutBucketPolicyInput{
		Bucket: aws.String("bucketname"),
		Policy: aws.String("{}"),
	})
	assertMD5(t, req)
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:8,代码来源:customizations_test.go

示例6: TestNoPopulateLocationConstraintIfClassic

func TestNoPopulateLocationConstraintIfClassic(t *testing.T) {
	s := s3.New(&aws.Config{Region: "us-east-1"})
	req, _ := s.CreateBucketRequest(&s3.CreateBucketInput{
		Bucket: aws.String("bucket"),
	})
	err := req.Build()
	assert.NoError(t, err)
	assert.Equal(t, 0, len(awsutil.ValuesAtPath(req.Params, "CreateBucketConfiguration.LocationConstraint")))
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:9,代码来源:bucket_location_test.go

示例7: TestNoPopulateLocationConstraintIfProvided

func TestNoPopulateLocationConstraintIfProvided(t *testing.T) {
	s := s3.New(nil)
	req, _ := s.CreateBucketRequest(&s3.CreateBucketInput{
		Bucket: aws.String("bucket"),
		CreateBucketConfiguration: &s3.CreateBucketConfiguration{},
	})
	err := req.Build()
	assert.NoError(t, err)
	assert.Equal(t, 0, len(awsutil.ValuesAtPath(req.Params, "CreateBucketConfiguration.LocationConstraint")))
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:10,代码来源:bucket_location_test.go

示例8: TestPopulateLocationConstraint

func TestPopulateLocationConstraint(t *testing.T) {
	s := s3.New(nil)
	in := &s3.CreateBucketInput{
		Bucket: aws.String("bucket"),
	}
	req, _ := s.CreateBucketRequest(in)
	err := req.Build()
	assert.NoError(t, err)
	assert.Equal(t, "mock-region", awsutil.ValuesAtPath(req.Params, "CreateBucketConfiguration.LocationConstraint")[0])
	assert.Nil(t, in.CreateBucketConfiguration) // don't modify original params
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:11,代码来源:bucket_location_test.go

示例9: TestMD5InDeleteObjects

func TestMD5InDeleteObjects(t *testing.T) {
	svc := s3.New(nil)
	req, _ := svc.DeleteObjectsRequest(&s3.DeleteObjectsInput{
		Bucket: aws.String("bucketname"),
		Delete: &s3.Delete{
			Objects: []*s3.ObjectIdentifier{
				{Key: aws.String("key")},
			},
		},
	})
	assertMD5(t, req)
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:12,代码来源:customizations_test.go

示例10: TestMD5InPutBucketTagging

func TestMD5InPutBucketTagging(t *testing.T) {
	svc := s3.New(nil)
	req, _ := svc.PutBucketTaggingRequest(&s3.PutBucketTaggingInput{
		Bucket: aws.String("bucketname"),
		Tagging: &s3.Tagging{
			TagSet: []*s3.Tag{
				{Key: aws.String("KEY"), Value: aws.String("VALUE")},
			},
		},
	})
	assertMD5(t, req)
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:12,代码来源:customizations_test.go

示例11: TestMD5InPutBucketCORS

func TestMD5InPutBucketCORS(t *testing.T) {
	svc := s3.New(nil)
	req, _ := svc.PutBucketCORSRequest(&s3.PutBucketCORSInput{
		Bucket: aws.String("bucketname"),
		CORSConfiguration: &s3.CORSConfiguration{
			CORSRules: []*s3.CORSRule{
				{AllowedMethods: []*string{aws.String("GET")}},
			},
		},
	})
	assertMD5(t, req)
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:12,代码来源:customizations_test.go

示例12: TestCopySourceSSECustomerKeyOverHTTPError

func TestCopySourceSSECustomerKeyOverHTTPError(t *testing.T) {
	s := s3.New(&aws.Config{DisableSSL: true})
	req, _ := s.CopyObjectRequest(&s3.CopyObjectInput{
		Bucket:     aws.String("bucket"),
		CopySource: aws.String("bucket/source"),
		Key:        aws.String("dest"),
		CopySourceSSECustomerKey: aws.String("key"),
	})
	err := req.Build()

	assert.Error(t, err)
	assert.Equal(t, "ConfigError", err.(awserr.Error).Code())
	assert.Contains(t, err.(awserr.Error).Message(), "cannot send SSE keys over HTTP")
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:14,代码来源:sse_test.go

示例13: init

// init will initialize all default options.
func (u *uploader) init() {
	if u.opts.S3 == nil {
		u.opts.S3 = s3.New(nil)
	}
	if u.opts.Concurrency == 0 {
		u.opts.Concurrency = DefaultUploadConcurrency
	}
	if u.opts.PartSize == 0 {
		u.opts.PartSize = DefaultUploadPartSize
	}

	// Try to get the total size for some optimizations
	u.initSize()
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:15,代码来源:upload.go

示例14: init

// init initializes the downloader with default options.
func (d *downloader) init() {
	d.totalBytes = -1

	if d.opts.Concurrency == 0 {
		d.opts.Concurrency = DefaultDownloadConcurrency
	}

	if d.opts.PartSize == 0 {
		d.opts.PartSize = DefaultDownloadPartSize
	}

	if d.opts.S3 == nil {
		d.opts.S3 = s3.New(nil)
	}
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:16,代码来源:download.go

示例15: TestMD5InPutBucketLifecycle

func TestMD5InPutBucketLifecycle(t *testing.T) {
	svc := s3.New(nil)
	req, _ := svc.PutBucketLifecycleRequest(&s3.PutBucketLifecycleInput{
		Bucket: aws.String("bucketname"),
		LifecycleConfiguration: &s3.LifecycleConfiguration{
			Rules: []*s3.LifecycleRule{
				{
					ID:     aws.String("ID"),
					Prefix: aws.String("Prefix"),
					Status: aws.String("Enabled"),
				},
			},
		},
	})
	assertMD5(t, req)
}
开发者ID:hadesbox,项目名称:aws-sdk-go,代码行数:16,代码来源:customizations_test.go


注:本文中的github.com/ks3sdklib/aws-sdk-go/service/s3.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。