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


Golang s3.New函数代码示例

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


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

示例1: SetConfig

func (e *environ) SetConfig(cfg *config.Config) error {
	ecfg, err := providerInstance.newConfig(cfg)
	if err != nil {
		return err
	}
	e.ecfgMutex.Lock()
	defer e.ecfgMutex.Unlock()
	e.ecfgUnlocked = ecfg

	auth := aws.Auth{ecfg.accessKey(), ecfg.secretKey()}
	region := aws.Regions[ecfg.region()]
	publicBucketRegion := aws.Regions[ecfg.publicBucketRegion()]
	e.ec2Unlocked = ec2.New(auth, region)
	e.s3Unlocked = s3.New(auth, region)

	// create new storage instances, existing instances continue
	// to reference their existing configuration.
	e.storageUnlocked = &storage{
		bucket: e.s3Unlocked.Bucket(ecfg.controlBucket()),
	}
	if ecfg.publicBucket() != "" {
		e.publicStorageUnlocked = &storage{
			bucket: s3.New(auth, publicBucketRegion).Bucket(ecfg.publicBucket()),
		}
	} else {
		e.publicStorageUnlocked = nil
	}
	return nil
}
开发者ID:CSRedRat,项目名称:juju-core,代码行数:29,代码来源:ec2.go

示例2: 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:whyrusleeping,项目名称:gobuilder,代码行数:27,代码来源:s3i_test.go

示例3: 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 err
	}
	defer file.Close()

	buffy := bufio.NewReader(file)
	stat, err := file.Stat()
	if err != nil {
		return 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 err
}
开发者ID:RoutineOp,项目名称:barkup,代码行数:32,代码来源:s3.go

示例4: TestCreateBucketBackward

func (s *S) TestCreateBucketBackward(c *gocheck.C) {
	patchRandomReader()
	defer unpatchRandomReader()
	auth := aws.Auth{AccessKey: "access", SecretKey: "s3cr3t"}
	region := aws.Region{
		Name:                 "myregion",
		S3Endpoint:           s.t.S3Server.URL(),
		S3LocationConstraint: true,
		S3LowercaseBucket:    true,
	}
	s3Client := s3.New(auth, region)
	app := App{Name: "leper"}
	err := s3Client.Bucket(app.Name).PutBucket(s3.BucketOwnerFull)
	c.Assert(err, gocheck.IsNil)
	env := s3Env{
		Auth:               aws.Auth{AccessKey: "access", SecretKey: "s3cr3t"},
		bucket:             app.Name,
		endpoint:           s.t.S3Server.URL(),
		locationConstraint: true,
	}
	ctx := action.BWContext{Params: []interface{}{&app}, FWResult: &env}
	createBucketAction.Backward(ctx)
	_, err = s3Client.Bucket(app.Name).List("", "/", "", 100)
	c.Assert(err, gocheck.NotNil)
}
开发者ID:rpeterson,项目名称:tsuru,代码行数:25,代码来源:actions_test.go

示例5: TestBootstrapInstanceIdHealerHeal

func (s *S) TestBootstrapInstanceIdHealerHeal(c *gocheck.C) {
	ec2Server, err := ec2test.NewServer()
	c.Assert(err, gocheck.IsNil)
	defer ec2Server.Quit()
	s3Server, err := s3test.NewServer(nil)
	c.Assert(err, gocheck.IsNil)
	defer s3Server.Quit()
	h := bootstrapInstanceIdHealer{}
	region := aws.SAEast
	region.EC2Endpoint = ec2Server.URL()
	region.S3Endpoint = s3Server.URL()
	h.e = ec2.New(aws.Auth{AccessKey: "some", SecretKey: "thing"}, region)
	sg, err := h.ec2().CreateSecurityGroup("juju-delta-0", "")
	c.Assert(err, gocheck.IsNil)
	h.s = s3.New(aws.Auth{AccessKey: "some", SecretKey: "thing"}, region)
	jujuBucket := "ble"
	config.Set("juju:bucket", jujuBucket)
	bucket := h.s3().Bucket(jujuBucket)
	err = bucket.PutBucket(s3.PublicReadWrite)
	c.Assert(err, gocheck.IsNil)
	resp, err := h.ec2().RunInstances(&ec2.RunInstances{MaxCount: 1, SecurityGroups: []ec2.SecurityGroup{sg.SecurityGroup}})
	c.Assert(err, gocheck.IsNil)
	err = bucket.Put("provider-state", []byte("doesnotexist"), "binary/octet-stream", s3.PublicReadWrite)
	c.Assert(err, gocheck.IsNil)
	c.Assert(h.needsHeal(), gocheck.Equals, true)
	err = h.Heal()
	c.Assert(err, gocheck.IsNil)
	data, err := bucket.Get("provider-state")
	expected := "zookeeper-instances: [" + resp.Instances[0].InstanceId + "]"
	c.Assert(string(data), gocheck.Equals, expected)
}
开发者ID:kaiquewdev,项目名称:tsuru,代码行数:31,代码来源:healer_test.go

示例6: PostSignup

func PostSignup(w *rest.ResponseWriter, req *rest.Request) {
	signup := Signup{}
	err := req.DecodeJsonPayload(&signup)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if signup.Email == "" {
		rest.Error(w, "email is required", 400)
		return
	}

	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}

	s := s3.New(auth, aws.EUWest)
	bucket := s.Bucket("seq-signup")
	data := []byte(signup.Email)
	err = bucket.Put(signup.Email, data, "text/plain", s3.BucketOwnerFull)
	if err != nil {
		panic(err.Error())
	}

	fmt.Println(signup)
	w.Header().Set("Access-Control-Allow-Origin", "http://sequenceiq.com")
	w.WriteJson(&signup)
}
开发者ID:sequenceiq,项目名称:go-signup,代码行数:29,代码来源:signup.go

示例7: CreateBucket

// Create the named bucket in the named region -- with the supplied creds
// and return the bucket *object
func CreateBucket(creds aws.Auth, region aws.Region, bucket_name string) *s3.Bucket {
	sss := s3.New(creds, region)
	bucket := sss.Bucket(bucket_name)
	log.Println("Creating s3 bucket")
	bucket.PutBucket(s3.Private)
	return bucket
}
开发者ID:reedobrien,项目名称:wpgo,代码行数:9,代码来源:sss.go

示例8: main

func main() {
	flag.Parse()

	cmds := flag.Args()

	if len(cmds) <= 0 {
		fmt.Println("Command required")
		os.Exit(1)
	}

	cmd := Cmd{}
	cmd.name = cmds[0]
	cmd.modifiers = cmds[1:]

	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err)
	}

	cmd.conn = s3.New(auth, getRegion(region))
	s3url, err := url.Parse(cmd.modifiers[0])
	cmd.url = s3url
	cmd.bucket = s3.Bucket{cmd.conn, cmd.url.Host}
	RunCommand(cmd)

}
开发者ID:jawnb,项目名称:s3tool,代码行数:26,代码来源:s3tool.go

示例9: main

func main() {
	flag.Parse()

	if *toHash == "" || *pkgDirs == "" || *cmd == "" || *bucketName == "" {
		log.Print("You are missing one or more mandatory command line arguments.")
		flag.Usage()
		os.Exit(1)
	}

	cred, err := aws.EnvAuth()
	if err != nil {
		log.Fatalf("Couldn't auth into s3. Did you set up ENV? Error: %s", err)
	}
	s3client := s3.New(cred, aws.USWest)
	bucket := s3client.Bucket(*bucketName)

	// extract.
	checksum := fmt.Sprintf("%x", hashFiles(*toHash).Sum(nil))

	filename := *outfile
	// consider bucket.GetReader to pipe directly into gunzip/untar
	file, err := bucket.Get(fmt.Sprintf("%s/%s", checksum, filename))
	if err != nil {
		fmt.Printf("%s\n", err)
		build(*cmd)
		archive(*pkgDirs, filename)
		upload(bucket, checksum, filename)
	} else {
		extract(file)
	}
}
开发者ID:justinabrahms,项目名称:gatherer,代码行数:31,代码来源:main.go

示例10: SetUpSuite

func (s *LocalServerSuite) SetUpSuite(c *C) {
	s.srv.SetUp(c)
	s.clientTests.s3 = s3.New(s.srv.auth, s.srv.region)

	// TODO Sadly the fake server ignores auth completely right now. :-(
	s.clientTests.authIsBroken = true
}
开发者ID:jiakuan,项目名称:goamz,代码行数:7,代码来源:s3t_test.go

示例11: readState

// Read the state from S3.
func readState() {
	state := State{}
	wd, err := os.Getwd()
	fmt.Printf("wd: %s\n", wd)

	// read from S3
	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}
	s := s3.New(auth, aws.USEast)
	bucket := s.Bucket(s3_bucket)
	data, err := bucket.Get("rss.json")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Data read from S3\n")

	// old way
	/*
		file, err := os.Open("state.json")
		if err != nil {
			panic(err)
		}
		data, err := ioutil.ReadAll(file)
		if err != nil {
			panic(err)
		}
	*/
	err = json.Unmarshal(data, &state)
	if err != nil {
		panic(err)
	}
	folders = state.Folders
}
开发者ID:swenson,项目名称:littlereader,代码行数:36,代码来源:reader.go

示例12: Deploy

// Deploys a site to S3.
func (s *Site) Deploy(user, pass, url string) error {
	auth := aws.Auth{AccessKey: user, SecretKey: pass}
	b := s3.New(auth, aws.USEast).Bucket(url)

	// walks _site directory and uploads file to S3
	walker := func(fn string, fi os.FileInfo, err error) error {
		if fi.IsDir() {
			return nil
		}

		rel, _ := filepath.Rel(s.Dest, fn)
		typ := mime.TypeByExtension(filepath.Ext(rel))
		content, err := ioutil.ReadFile(fn)
		log.Printf(MsgUploadFile, rel)
		if err != nil {
			return err
		}

		// try to upload the file ... sometimes this fails due to amazon
		// issues. If so, we'll re-try
		if err := b.Put(rel, content, typ, s3.PublicRead); err != nil {
			time.Sleep(100 * time.Millisecond) // sleep so that we don't immediately retry
			return b.Put(rel, content, typ, s3.PublicRead)
		}

		// file upload was a success, return nil
		return nil
	}

	return filepath.Walk(s.Dest, walker)
}
开发者ID:htruong,项目名称:oryza,代码行数:32,代码来源:site.go

示例13: saver

// Goroutine for saving the state.
func saver(ticker *time.Ticker) {
	for {
		select {
		case <-ticker.C:
			println("Writing state")
			lock.Lock()
			if dirty {
				dirty = false
				state := State{folders}

				bytes, err := json.Marshal(state)
				if err != nil {
					panic(err)
				}

				// write to S3
				auth, err := aws.EnvAuth()
				if err != nil {
					panic(err)
				}
				s := s3.New(auth, aws.USEast)
				bucket := s.Bucket(s3_bucket)
				err = bucket.Put("rss.json", bytes, "application/json", s3.ACL("private"))
				if err != nil {
					panic(err)
				}
			}
			lock.Unlock()
		}
	}
}
开发者ID:swenson,项目名称:littlereader,代码行数:32,代码来源:reader.go

示例14: Sync

func Sync(localPath, bucketName, awsRegion, acl string) {
	if localPath == "" || bucketName == "" {
		flag.PrintDefaults()
		return
	}
	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}
	s3Conn := s3.New(auth, aws.Regions[awsRegion])
	bucket := s3Conn.Bucket(bucketName)
	pathChan := make(chan string)
	doneChan := make(chan int)
	go doTheWalk(localPath, pathChan)
	count := 0
	for path := range pathChan {
		if path == "" {
			break
		}
		go compareAndSync(acl, localPath, path, bucket, doneChan)
		count++
	}
	for i := 0; i < count; i++ {
		<-doneChan
	}
}
开发者ID:rossdylan,项目名称:3sync,代码行数:26,代码来源:3sync.go

示例15: SetUpSuite

func (s *AmazonClientSuite) SetUpSuite(c *C) {
	if !*amazon {
		c.Skip("live tests against AWS disabled (no -amazon)")
	}
	s.srv.SetUp(c)
	s.s3 = s3.New(s.srv.auth, s.Region)
}
开发者ID:felixge,项目名称:goamz,代码行数:7,代码来源:s3i_test.go


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