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


Golang s3gof3r.New函数代码示例

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


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

示例1: Download

func (s *S3) Download(remote_path, local_path string, uid, gid int, perms, listener string) error {
	log.Infof("S3 Downloading %s", local_path)
	conf, keys := s.GetS3Config()

	// Open bucket to put file into
	s3 := s3gof3r.New("", *keys)
	b := s3.Bucket(s.config.Listeners[s.listener].Bucket)

	r, _, err := b.GetReader(remote_path, conf)
	if err != nil {
		return err
	}
	// stream to file
	if _, err = utils.FileWrite(local_path, r, uid, gid, perms); err != nil {
		return err
	}
	err = r.Close()
	if err != nil {
		return err
	}
	basePath := s.config.Listeners[listener].BasePath
	datastore.UpdateHost(listener, strings.TrimLeft(local_path, basePath))

	return err
}
开发者ID:huuzkee-foundation,项目名称:gosync,代码行数:25,代码来源:s3.go

示例2: main

func main() {

	s3gof3r.SetLogger(os.Stdout, "", log.LstdFlags, false)

	// STARTEXAMPLE OMIT
	presentation, err := os.Open(file_name) // open presentation file
	if err != nil {
		log.Fatal(err)
	}

	k, err := s3gof3r.EnvKeys() // get S3 keys from environment
	if err != nil {
		log.Fatal(err)
	}
	// Open bucket to put file into
	s3 := s3gof3r.New("", k)
	b := s3.Bucket(bucket_name)

	// Open a PutWriter for upload
	w, err := b.PutWriter(presentation.Name(), nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	defer w.Close()
	if _, err = io.Copy(w, presentation); err != nil { // Copy into S3
		log.Fatal(err)
	}
	log.Printf("%s uploaded to %s", file_name, bucket_name)
	// STOPEXAMPLE OMIT
}
开发者ID:rlmcpherson,项目名称:gophercon_lightning_talk,代码行数:30,代码来源:example.go

示例3: reloc

func reloc(bucketName, oldPath, newPath string, keys s3gof3r.Keys) {
	s3 := s3gof3r.New("s3.amazonaws.com", keys)
	bucket := s3.Bucket(bucketName)
	// this is a POST at the bottom, and copies are a PUT.  whee.
	//w, err := s3.Bucket(bucketName).PutWriter(newPath, copyInstruction, s3Conf)
	// So, implement our own aws copy API.
	req, err := http.NewRequest("PUT", "", &bytes.Buffer{})
	if err != nil {
		panic(integrity.WarehouseConnectionError.Wrap(err))
	}
	req.URL.Scheme = s3Conf.Scheme
	req.URL.Host = fmt.Sprintf("%s.%s", bucketName, s3.Domain)
	req.URL.Path = path.Clean(fmt.Sprintf("/%s", newPath))
	// Communicate the copy source object with a header.
	// Be advised that if this object doesn't exist, amazon reports that as a 404... yes, a 404 that has nothing to do with the query URI.
	req.Header.Add("x-amz-copy-source", path.Join("/", bucketName, oldPath))
	bucket.Sign(req)
	resp, err := s3Conf.Client.Do(req)
	if err != nil {
		panic(integrity.WarehouseConnectionError.Wrap(err))
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		panic(integrity.WarehouseConnectionError.Wrap(newRespError(resp)))
	}
	// delete previous location
	if err := bucket.Delete(oldPath); err != nil {
		panic(integrity.WarehouseConnectionError.Wrap(err))
	}
}
开发者ID:kkroening,项目名称:repeatr,代码行数:30,代码来源:s3_stream.go

示例4: Upload

func (s *S3) Upload(local_path, remote_path string) error {
	conf, keys := s.GetS3Config()

	// Open bucket to put file into
	s3 := s3gof3r.New("", *keys)
	b := s3.Bucket(s.config.Listeners[s.listener].Bucket)

	// open file to upload
	file, err := os.Open(local_path)
	if err != nil {
		return err
	}

	// Open a PutWriter for upload
	w, err := b.PutWriter(remote_path, nil, conf)
	if err != nil {
		return err
	}
	if _, err = io.Copy(w, file); err != nil { // Copy into S3
		return err
	}
	if err = w.Close(); err != nil {
		return err
	}
	return nil

}
开发者ID:huuzkee-foundation,项目名称:gosync,代码行数:27,代码来源:s3.go

示例5: DownloadFromS3

func DownloadFromS3(k s3gof3r.Keys, bucketName, filename string) (bytes.Buffer, error) {
	s3 := s3gof3r.New("", k)
	b := s3.Bucket(bucketName)

	r, _, err := b.GetReader(filename, nil)
	if err != nil {
		return bytes.Buffer{}, err
	}

	// outputFile, err := os.Create(filepath.Join(outputDirPath, filename))
	// if err != nil {
	// 	return nil, err
	// }

	var output bytes.Buffer

	if _, err = io.Copy(&output, r); err != nil {
		return bytes.Buffer{}, err
	}

	err = r.Close()
	if err != nil {
		return bytes.Buffer{}, err
	}

	return output, nil
}
开发者ID:headmade,项目名称:backuper,代码行数:27,代码来源:util.go

示例6: Execute

func (rm *rmOpts) Execute(args []string) error {

	k, err := getAWSKeys()
	if err != nil {
		return err
	}

	conf := new(s3gof3r.Config)
	*conf = *s3gof3r.DefaultConfig
	s3 := s3gof3r.New(rm.EndPoint, k)
	s3gof3r.SetLogger(os.Stderr, "", log.Ltime, rm.Debug)

	// parse positional cp args
	if len(args) != 1 {
		return fmt.Errorf("rm: path argument required")
	}

	//var urls [1]*url.URL
	u, err := url.ParseRequestURI(args[0])
	if err != nil {
		return fmt.Errorf("parse error: %s", err)
	}
	if u.Host != "" && u.Scheme != "s3" {
		return fmt.Errorf("parse error: %s", u.String())
	}
	return s3.Bucket(u.Host).Delete(u.Path)
}
开发者ID:elblivion,项目名称:s3gof3r,代码行数:27,代码来源:rm.go

示例7: UploadToS3

func UploadToS3(k s3gof3r.Keys, bucketName string, pathToFile string) error {
	s3 := s3gof3r.New("", k)
	b := s3.Bucket(bucketName)

	file, err := os.Open(pathToFile)
	if err != nil {
		return err
	}

	stats, _ := file.Stat()

	dstPath := FormatDstPath("/backup/%hostname%/%timestamp%", stats.Name())

	w, err := b.PutWriter(dstPath, nil, nil)
	if err != nil {
		return err
	}

	if _, err = io.Copy(w, file); err != nil { // Copy into S3
		return err
	}

	if err = w.Close(); err != nil {
		return err
	}

	return nil
}
开发者ID:headmade,项目名称:backuper,代码行数:28,代码来源:util.go

示例8: SafeCreateS3Bucket

//SafeCreateS3Bucket creates an s3 bucket for storing files to an s3-compatible blobstore
func SafeCreateS3Bucket(domain, bucket, accessKey, secretKey string) (*S3Bucket, error) {
	s := &S3Bucket{
		Bucket:    bucket,
		Name:      "s3",
		Domain:    domain,
		AccessKey: accessKey,
		SecretKey: secretKey,
	}
	if s.Bucket == "" {
		return nil, errors.New("bucket name is undefined")
	}
	var k s3gof3r.Keys
	var err error

	if s.AccessKey == "" || s.SecretKey == "" {
		k, err = s3gof3r.EnvKeys() // get S3 keys from environment
		if err != nil {
			return nil, err
		}
	} else {
		k = s3gof3r.Keys{
			AccessKey: s.AccessKey,
			SecretKey: s.SecretKey,
		}
	}
	s3 := s3gof3r.New(s.Domain, k)
	s.bucket = s3.Bucket(s.Bucket)
	return s, nil
}
开发者ID:kevball,项目名称:cfops,代码行数:30,代码来源:s3.go

示例9: makeS3writer

func makeS3writer(bucketName string, path string, keys s3gof3r.Keys) io.WriteCloser {
	s3 := s3gof3r.New("s3.amazonaws.com", keys)
	w, err := s3.Bucket(bucketName).PutWriter(path, nil, s3Conf)
	if err != nil {
		panic(integrity.WarehouseConnectionError.Wrap(err))
	}
	return w
}
开发者ID:kkroening,项目名称:repeatr,代码行数:8,代码来源:s3_stream.go

示例10: Execute

func (cp *cpOpts) Execute(args []string) (err error) {

	k, err := getAWSKeys()
	if err != nil {
		return
	}

	conf := new(s3gof3r.Config)
	*conf = *s3gof3r.DefaultConfig
	s3 := s3gof3r.New(cp.EndPoint, k)
	conf.Concurrency = cp.Concurrency
	if cp.NoSSL {
		conf.Scheme = "http"
	}
	conf.PartSize = cp.PartSize
	conf.Md5Check = !cp.NoMd5
	s3gof3r.SetLogger(os.Stderr, "", log.LstdFlags, cp.Debug)

	src, err := func(src string) (io.ReadCloser, error) {
		u, err := url.Parse(src)
		if err != nil {
			return nil, fmt.Errorf("parse error: %s", err)
		}

		if u.Host == "" {
			return os.Open(u.Path)
		}
		r, _, err := s3.Bucket(u.Host).GetReader(u.Path, conf)
		return r, err
	}(cp.Source)
	if err != nil {
		return
	}

	dst, err := func(dst string) (io.WriteCloser, error) {
		u, err := url.Parse(dst)
		if err != nil {
			return nil, fmt.Errorf("parse error: %s", err)
		}

		if u.Host == "" {
			return os.Create(u.Path)
		}

		return s3.Bucket(u.Host).PutWriter(u.Path, ACL(cp.Header, cp.ACL), conf)
	}(cp.Dest)
	if err != nil {
		return
	}

	if _, err = io.Copy(dst, src); err != nil {
		return
	}
	if err = src.Close(); err != nil {
		return
	}
	return dst.Close()
}
开发者ID:huuzkee-foundation,项目名称:gosync,代码行数:58,代码来源:cp.go

示例11: Remove

func (s *S3) Remove(remote_path string) bool {
	log.Infof("Removing file %s from s3 storage", remote_path)
	_, keys := s.GetS3Config()

	// Open bucket to put file into
	s3 := s3gof3r.New("", *keys)
	b := s3.Bucket(s.config.Listeners[s.listener].Bucket)
	b.Delete(remote_path)
	return true
}
开发者ID:huuzkee-foundation,项目名称:gosync,代码行数:10,代码来源:s3.go

示例12: Execute

func (cp *cpOpts) Execute(args []string) (err error) {

	k, err := getAWSKeys()
	if err != nil {
		return
	}

	conf := new(s3gof3r.Config)
	*conf = *s3gof3r.DefaultConfig
	s3 := s3gof3r.New(cp.EndPoint, k)
	conf.Concurrency = cp.Concurrency
	if cp.NoSSL {
		conf.Scheme = "http"
	}
	conf.PartSize = cp.PartSize
	conf.Md5Check = !cp.NoMd5
	conf.NTry = cp.NTry
	s3gof3r.SetLogger(os.Stderr, "", log.LstdFlags, cp.Debug)

	src, err := func(src string) (io.ReadCloser, error) {
		if !strings.HasPrefix(strings.ToLower(src), "s3") {
			return os.Open(src)
		}
		u, err := url.ParseRequestURI(src)
		if err != nil {
			return nil, fmt.Errorf("parse error: %s", err)
		}

		r, _, err := s3.Bucket(u.Host).GetReader(u.Path, conf)
		return r, err
	}(cp.Source)
	if err != nil {
		return
	}
	defer checkClose(src, err)

	dst, err := func(dst string) (io.WriteCloser, error) {
		if !strings.HasPrefix(strings.ToLower(dst), "s3") {
			return os.Create(dst)
		}
		u, err := url.ParseRequestURI(dst)
		if err != nil {
			return nil, fmt.Errorf("parse error: %s", err)
		}

		return s3.Bucket(u.Host).PutWriter(u.Path, ACL(cp.Header, cp.ACL), conf)
	}(cp.Dest)
	if err != nil {
		return
	}

	defer checkClose(dst, err)
	_, err = io.Copy(dst, src)
	return
}
开发者ID:rlmcpherson,项目名称:s3gof3r,代码行数:55,代码来源:cp.go

示例13: makeS3reader

func makeS3reader(bucketName string, path string, keys s3gof3r.Keys) io.ReadCloser {
	s3 := s3gof3r.New("s3.amazonaws.com", keys)
	w, _, err := s3.Bucket(bucketName).GetReader(path, s3Conf)
	if err != nil {
		if err2, ok := err.(*s3gof3r.RespError); ok && err2.Code == "NoSuchKey" {
			panic(integrity.DataDNE.New("not stored here"))
		} else {
			panic(integrity.WarehouseConnectionError.Wrap(err))
		}
	}
	return w
}
开发者ID:kkroening,项目名称:repeatr,代码行数:12,代码来源:s3_stream.go

示例14: newS3WriterProvider

func newS3WriterProvider(awsAccessKey string, awsSecretKey string, s3Domain string, bucketName string) *S3WriterProvider {
	s3gof3r.DefaultDomain = s3Domain

	awsKeys := s3gof3r.Keys{
		AccessKey: awsAccessKey,
		SecretKey: awsSecretKey,
	}

	s3 := s3gof3r.New("", awsKeys)
	bucket := s3.Bucket(bucketName)

	return &S3WriterProvider{bucket}
}
开发者ID:Financial-Times,项目名称:coco-mongodb-backup,代码行数:13,代码来源:s3_provider.go

示例15: NewS3Remote

func NewS3Remote(config config.Config) (*S3Remote, error) {
	s3, err := newS3Client(config)
	if err != nil {
		return &S3Remote{}, err
	}

	s3gof3rKeys := s3gof3r.Keys{AccessKey: config.AWS.AccessKeyID, SecretKey: config.AWS.SecretAccessKey}

	return &S3Remote{
		config:               config,
		BucketName:           config.AWS.S3URL.Host,
		client:               s3,
		uploadDownloadClient: s3gof3r.New("", s3gof3rKeys),
	}, nil
}
开发者ID:sbecker,项目名称:dogestry,代码行数:15,代码来源:s3.go


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