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


Golang s3.New函數代碼示例

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


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

示例1: CreateBucket

func CreateBucket() *s3.Bucket {
	auth, err := aws.EnvAuth()
	if err != nil {
		println("store -- error connecting to AWS\n")
		panic(err)
	}

	fmt.Printf("store -- connected to AWS\n")

	awsRegion := os.Getenv("STORE_AWSREGION")
	if awsRegion == "" {
		println("store -- error: environment variable STORE_AWSREGION not set")
		panic("store -- STORE_AWSREGION not set")
	}

	region := aws.Regions[awsRegion]
	if region.Name == "" {
		panic("store -- region '" + awsRegion + "' is invalid")
	}
	println("store -- AWS region: " + region.Name)

	S3 := s3.New(auth, aws.Regions["eu-west-1"])

	bucketName := os.Getenv("STORE_BUCKETNAME")
	if bucketName == "" {
		println("store -- error: environment variable STORE_BUCKETNAME not set")
		panic("store -- STORE_BUCKETNAME not set")
	}

	bucket := S3.Bucket(bucketName)
	println("store -- Bucket name: " + bucket.Name)
	return bucket
}
開發者ID:erlendr,項目名稱:store,代碼行數:33,代碼來源:store.go

示例2: SendImage

func (gozo Gozo) SendImage(filename string) (url string, err error) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return
	}

	auth, err := aws.GetAuth(
		gozo.accessKey,
		gozo.secretAccessKey,
	)
	if err != nil {
		return
	}

	s3client := s3.New(auth, gozo.region)
	bucket := s3client.Bucket(gozo.bucketName)

	path := "images/" + hexdigest(fmt.Sprintf("%s-%d", filename, time.Now().Unix())) + ".png"
	err = bucket.Put(path, data, "image/png", s3.PublicRead)
	if err != nil {
		return
	}

	url = gozo.rootURL + path
	return
}
開發者ID:naoya,項目名稱:Gozo,代碼行數:26,代碼來源:gozo.go

示例3: Configure

func (p *PostProcessor) Configure(raws ...interface{}) error {
	err := config.Decode(&p.config, &config.DecodeOpts{
		Interpolate:        true,
		InterpolateContext: &p.config.ctx,
		InterpolateFilter: &interpolate.RenderFilter{
			Exclude: []string{"output"},
		},
	}, raws...)
	if err != nil {
		return err
	}

	errs := new(packer.MultiError)
	// required configuration
	templates := map[string]*string{
		"region":   &p.config.Region,
		"bucket":   &p.config.Bucket,
		"manifest": &p.config.ManifestPath,
		"box_name": &p.config.BoxName,
		"box_dir":  &p.config.BoxDir,
		"version":  &p.config.Version,
	}

	for key, ptr := range templates {
		if *ptr == "" {
			errs = packer.MultiErrorAppend(errs, fmt.Errorf("vagrant-s3 %s must be set", key))
		}
	}

	// Template process
	for key, ptr := range templates {
		if err = interpolate.Validate(*ptr, &p.config.ctx); err != nil {
			errs = packer.MultiErrorAppend(
				errs, fmt.Errorf("Error parsing %s template: %s", key, err))
		}
	}

	auth, err := aws.GetAuth(p.config.AccessKey, p.config.SecretKey)
	if err != nil {
		errs = packer.MultiErrorAppend(errs, fmt.Errorf("Unable to create Aws Authentication. Try providing keys 'access_key_id' and 'secret_key'"))
	}

	// determine region
	region, valid := aws.Regions[p.config.Region]
	if valid {
		p.s3 = s3.New(auth, region).Bucket(p.config.Bucket)
	} else {
		errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid region specified: %s", p.config.Region))
	}

	if p.config.ACL == "" {
		p.config.ACL = "public-read"
	}

	if len(errs.Errors) > 0 {
		return errs
	}

	return nil
}
開發者ID:clofresh,項目名稱:packer-post-processor-vagrant-s3,代碼行數:60,代碼來源:post-processor.go

示例4: Configure

func (p *PostProcessor) Configure(raws ...interface{}) error {
	err := config.Decode(&p.config, &config.DecodeOpts{
		Interpolate:        true,
		InterpolateContext: &p.config.ctx,
		InterpolateFilter: &interpolate.RenderFilter{
			Exclude: []string{},
		},
	}, raws...)
	if err != nil {
		return err
	}

	errs := &packer.MultiError{}

	errs = packer.MultiErrorAppend(errs, p.config.AccessConfig.Prepare(&p.config.ctx)...)

	// required configuration
	templates := map[string]*string{
		"region":   &p.config.Region,
		"bucket":   &p.config.Bucket,
		"manifest": &p.config.ManifestPath,
		"box_name": &p.config.BoxName,
		"box_dir":  &p.config.BoxDir,
		"version":  &p.config.Version,
	}

	// Template process
	for key, ptr := range templates {
		if *ptr == "" {
			errs = packer.MultiErrorAppend(
				errs, fmt.Errorf("%s must be set", key))
		}

		*ptr, err = interpolate.Render(*ptr, &p.config.ctx)
		if err != nil {
			errs = packer.MultiErrorAppend(
				errs, fmt.Errorf("Error processing %s: %s", key, err))
		}
	}

	// setup the s3 bucket
	auth, err := aws.GetAuth(p.config.AccessConfig.AccessKey, p.config.AccessConfig.SecretKey)
	if err != nil {
		errs = packer.MultiErrorAppend(errs, err)
	}

	// determine region
	region, valid := aws.Regions[p.config.Region]
	if valid {
		p.s3 = s3.New(auth, region).Bucket(p.config.Bucket)
	} else {
		errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid region specified: %s", p.config.Region))
	}

	if len(errs.Errors) > 0 {
		return errs
	}

	return nil
}
開發者ID:kadaan,項目名稱:packer-post-processor-vagrant-s3,代碼行數:60,代碼來源:post-processor.go

示例5: UploadToS3

func UploadToS3(file multipart.File, s3Key string) (err error) {

	auth, err := aws.EnvAuth()
	if err != nil {
		log.Fatal("Incorrect AWS Auth Details ", err)
	}

	connection := s3.New(auth, region)
	bucket := connection.Bucket(os.Getenv("S3_BUCKET"))

	buffer := new(bytes.Buffer)
	_, err = io.Copy(buffer, file)
	if err != nil {
		log.Fatal("Cannot create file ", err)
	}

	filetype := http.DetectContentType(buffer.Bytes())
	err = bucket.Put(
		s3Key,
		buffer.Bytes(),
		filetype,
		s3.ACL("public-read"),
	)
	return err
}
開發者ID:eddturtle,項目名稱:imagio,代碼行數:25,代碼來源:aws.go

示例6: FromSource

func FromSource(source models.Source) (Driver, error) {
	var initialVersion semver.Version
	if source.InitialVersion != "" {
		version, err := semver.Parse(source.InitialVersion)
		if err != nil {
			return nil, fmt.Errorf("invalid initial version (%s): %s", source.InitialVersion, err)
		}

		initialVersion = version
	} else {
		initialVersion = semver.Version{Major: 0, Minor: 0, Patch: 0}
	}

	switch source.Driver {
	case models.DriverUnspecified, models.DriverS3:
		auth := aws.Auth{
			AccessKey: source.AccessKeyID,
			SecretKey: source.SecretAccessKey,
		}

		regionName := source.RegionName
		if len(regionName) == 0 {
			regionName = aws.USEast.Name
		}

		region, ok := aws.Regions[regionName]
		if !ok {
			return nil, errors.New(fmt.Sprintf("no such region '%s'", regionName))
		}

		if len(source.Endpoint) != 0 {
			region = aws.Region{
				S3Endpoint: fmt.Sprintf("https://%s", source.Endpoint),
			}
		}

		client := s3.New(auth, region)
		bucket := client.Bucket(source.Bucket)

		return &S3Driver{
			InitialVersion: initialVersion,

			Bucket: bucket,
			Key:    source.Key,
		}, nil

	case models.DriverGit:
		return &GitDriver{
			InitialVersion: initialVersion,

			URI:        source.URI,
			Branch:     source.Branch,
			PrivateKey: source.PrivateKey,
			File:       source.File,
		}, nil

	default:
		return nil, fmt.Errorf("unknown driver: %s", source.Driver)
	}
}
開發者ID:xtreme-sameer-vohra,項目名稱:semver-resource,代碼行數:60,代碼來源:driver.go

示例7: TestRegions

// Communicate with all endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *C) {
	errs := make(chan error, len(aws.Regions))
	for _, region := range aws.Regions {
		go func(r aws.Region) {
			s := s3.New(s.s3.Auth, r)
			b := s.Bucket("goamz-" + s.Auth.AccessKey)
			_, err := b.Get("non-existent")
			errs <- err
		}(region)
	}
	for _ = range aws.Regions {
		err := <-errs
		if err != nil {
			s3_err, ok := err.(*s3.Error)
			if ok {
				c.Check(s3_err.Code, Matches, "NoSuchBucket")
			} else if _, ok = err.(*net.DNSError); ok {
				// Okay as well.
			} else {
				c.Errorf("Non-S3 error: %s", err)
			}
		} else {
			c.Errorf("Test should have errored but it seems to have succeeded")
		}
	}
}
開發者ID:evaluation-alex,項目名稱:gosync,代碼行數:27,代碼來源:s3i_test.go

示例8: PutS3File

func PutS3File(pushAuth *aws.Auth, localFilePath, s3URL, contentType string) error {
	urlParsed, err := url.Parse(s3URL)
	if err != nil {
		return err
	}

	if urlParsed.Scheme != "s3" {
		return fmt.Errorf("Don't know how to use URL with scheme %v", urlParsed.Scheme)
	}

	localFileReader, err := os.Open(localFilePath)
	if err != nil {
		return err
	}

	fi, err := os.Stat(localFilePath)
	if err != nil {
		return err
	}

	session := s3.New(*pushAuth, aws.USEast)
	bucket := session.Bucket(urlParsed.Host)
	err = bucket.PutReader(urlParsed.Path, localFileReader, fi.Size(), contentType, s3.PublicRead)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:MauroJr,項目名稱:evergreen,代碼行數:28,代碼來源:s3.go

示例9: Put

// Put the specified resource to s3.
func (self *S3PutCommand) Put() error {

	fi, err := os.Stat(self.LocalFile)
	if err != nil {
		return err
	}

	fileReader, err := os.Open(self.LocalFile)
	if err != nil {
		return err
	}
	defer fileReader.Close()

	// get the appropriate session and bucket
	auth := &aws.Auth{
		AccessKey: self.AwsKey,
		SecretKey: self.AwsSecret,
	}
	session := s3.New(*auth, aws.USEast)
	bucket := session.Bucket(self.Bucket)

	// put the data
	return bucket.PutReader(
		self.RemoteFile,
		fileReader,
		fi.Size(),
		self.ContentType,
		s3.ACL(self.Permissions),
	)

}
開發者ID:MauroJr,項目名稱:evergreen,代碼行數:32,代碼來源:put_command.go

示例10: awsConnectForTest

func awsConnectForTest() *s3.Bucket {
	os.Setenv("AWS_ACCESS_KEY_ID", Config.Aws.AccessKeyId)
	os.Setenv("AWS_SECRET_ACCESS_KEY", Config.Aws.SecretAccessKey)
	auth, err := aws.EnvAuth()
	perror(err)
	return s3.New(auth, aws.Regions[Config.Aws.Region]).Bucket(Config.Aws.BucketName)
}
開發者ID:memikequinn,項目名稱:lfs-server-go,代碼行數:7,代碼來源:aws_content_store_test.go

示例11: uploadToS3

func uploadToS3(file string, s3_bucket string, awsRegion aws.Region) error {
	log.Println("Uploading to S3...")
	auth, err := aws.EnvAuth()
	if err != nil {
		return err
	}
	client := s3.New(auth, awsRegion)
	bucket := client.Bucket(s3_bucket)

	r, errF := os.Open(file)
	fi, _ := r.Stat()
	length := fi.Size()

	if errF != nil {
		return errF
	}

	path := file
	perm := s3.ACL("private")
	contType := "application/x-compressed"

	err = bucket.PutReader(path, r, length, contType, perm)
	if err != nil {
		return err
	}

	log.Println("Upload successful")
	return nil
}
開發者ID:hybris,項目名稱:zk-backup,代碼行數:29,代碼來源:zk-backup.go

示例12: Store

// Store puts an `ExportResult` struct to an S3 bucket within the specified directory
func (x *S3) Store(result *ExportResult, directory string) *Error {

	if result.Error != nil {
		return result.Error
	}

	file, err := os.Open(result.Path)
	if err != nil {
		return makeErr(err, "")
	}
	defer file.Close()

	buffy := bufio.NewReader(file)
	stat, err := file.Stat()
	if err != nil {
		return makeErr(err, "")
	}

	size := stat.Size()

	auth := aws.Auth{
		AccessKey: x.AccessKey,
		SecretKey: x.ClientSecret,
	}

	s := s3.New(auth, aws.Regions[x.Region])
	bucket := s.Bucket(x.Bucket)

	err = bucket.PutReader(directory+result.Filename(), buffy, size, result.MIME, s3.BucketOwnerFull)
	return makeErr(err, "")
}
開發者ID:adcombi,項目名稱:barkup,代碼行數:32,代碼來源:s3.go

示例13: getS3Bucket

func getS3Bucket(accessKey, secretKey, bucket string) *s3.Bucket {
	auth := aws.Auth{
		AccessKey: accessKey,
		SecretKey: secretKey,
	}
	return s3.New(auth, aws.USEast).Bucket(bucket)
}
開發者ID:palaiyacw,項目名稱:imgry,代碼行數:7,代碼來源:util.go

示例14: main

func main() {
	var err error
	var match = flag.String("match", "", "pattern to match when listing keys")

	flag.Parse()
	args := flag.Args()

	auth, err := aws.SharedAuth()
	if err != nil {
		fmt.Fprintf(os.Stderr, "unable to authenticate: %s\n", err.Error())
		os.Exit(1)
	}

	client := s3.New(auth, aws.USEast)

	if len(args) == 0 {
		err = listBuckets(client, *match)
	} else {
		err = listObjectsInBuckets(client, args, *match)
	}
	if err != nil {
		fmt.Fprintf(os.Stderr, err.Error())
		os.Exit(1)
	}

}
開發者ID:justinwalz,項目名稱:ss3,代碼行數:26,代碼來源:main.go

示例15: setupS3Backend

func setupS3Backend(t *testing.T) *bes3.S3Backend {
	s.config = &s3test.Config{
		Send409Conflict: true,
	}
	srv, err := s3test.NewServer(s.config)
	OK(t, err)
	s.srv = srv

	s.region = aws.Region{
		Name:                 "faux-region-1",
		S3Endpoint:           srv.URL(),
		S3LocationConstraint: true, // s3test server requires a LocationConstraint
	}

	s.auth = aws.Auth{"abc", "123", ""}

	service := s3.New(s.auth, s.region)
	bucket := service.Bucket("testbucket")
	err = bucket.PutBucket("private")
	OK(t, err)

	t.Logf("created s3 backend locally")

	return bes3.OpenS3Bucket(bucket, "testbucket")
}
開發者ID:rawtaz,項目名稱:restic,代碼行數:25,代碼來源:s3_test.go


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