• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang s3gof3r.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Execute

func (get *Get) Execute(args []string) (err error) {
	conf := new(s3gof3r.Config)
	*conf = *s3gof3r.DefaultConfig
	k, err := getAWSKeys()
	if err != nil {
		return
	}
	s3 := s3gof3r.New(get.EndPoint, k)
	b := s3.Bucket(get.Bucket)
	if get.Concurrency > 0 {
		conf.Concurrency = get.Concurrency
	}
	conf.PartSize = get.PartSize
	conf.Md5Check = !get.CheckDisable
	get.Key = url.QueryEscape(get.Key)

	if get.VersionId != "" {
		get.Key = fmt.Sprintf("%s?versionId=%s", get.Key, get.VersionId)
	}
	log.Println("GET: ", get)

	w, err := os.Create(get.Path)
	if err != nil {
		if get.Path == "" {
			w = os.Stdout
		} else {
			return
		}
	}
	defer w.Close()
	r, header, err := b.GetReader(get.Key, conf)
	if err != nil {
		return
	}
	if _, err = io.Copy(w, r); err != nil {
		return
	}
	if err = r.Close(); err != nil {
		return
	}
	log.Println("Headers: ", header)
	if get.Debug {
		debug()
	}
	return
}
开发者ID:kconnor,项目名称:s3gof3r,代码行数:46,代码来源:get.go


示例17: Execute

func (get *getOpts) Execute(args []string) (err error) {
	conf := new(s3gof3r.Config)
	*conf = *s3gof3r.DefaultConfig
	k, err := getAWSKeys()
	if err != nil {
		return
	}
	s3 := s3gof3r.New(get.EndPoint, k)
	b := s3.Bucket(get.Bucket)
	conf.Concurrency = get.Concurrency
	if get.NoSSL {
		conf.Scheme = "http"
	}
	conf.PartSize = get.PartSize
	conf.Md5Check = !get.NoMd5

	s3gof3r.SetLogger(os.Stderr, "", log.LstdFlags, get.Debug)

	if get.VersionID != "" {
		get.Key = fmt.Sprintf("%s?versionId=%s", get.Key, get.VersionID)
	}

	w, err := os.Create(get.Path)
	if err != nil {
		if get.Path == "" {
			w = os.Stdout
		} else {
			return
		}
	}
	defer w.Close()
	r, header, err := b.GetReader(get.Key, conf)
	if err != nil {
		return
	}
	if _, err = io.Copy(w, r); err != nil {
		return
	}
	if err = r.Close(); err != nil {
		return
	}
	if get.Debug {
		log.Println("Headers: ", header)
	}
	return
}
开发者ID:zhujo01,项目名称:s3gof3r,代码行数:46,代码来源:get.go


示例18: NewS3Remote

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

	s3gof3rKeys, err := getS3gof3rKeys(config)
	if err != nil {
		return &S3Remote{}, err
	}

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


示例19: newUploadDownlaodClient

func newUploadDownlaodClient(config config.Config) (*s3gof3r.S3, error) {
	s3gKeys, err := getS3gof3rKeys(config)
	if err != nil {
		return nil, err
	}

	var s3domain string

	// We have to do this due to a recent region related change in s3gof3r:
	// https://github.com/rlmcpherson/s3gof3r/blob/b574ee38528c51c2c8652b79e71245817c59bd61/s3gof3r.go#L28-L43
	if config.AWS.Region == "us-east-1" {
		s3domain = ""
	} else {
		s3domain = fmt.Sprintf("s3-%v.amazonaws.com", config.AWS.Region)
	}

	return s3gof3r.New(s3domain, s3gKeys), nil
}
开发者ID:number9code,项目名称:dogestry,代码行数:18,代码来源:s3.go


示例20: newS3Output

func newS3Output(conf map[string]string) (output, error) {
	bucketName := conf["bucket"]
	if bucketName == "" {
		return nil, errors.New("No bucket specified")
	}
	fileName := conf["filename"]
	if fileName == "" {
		return nil, errors.New("No file name specified")
	}

	keys, err := s3gof3r.EnvKeys()
	if err != nil {
		return nil, err
	}
	s3 := s3gof3r.New(conf["endpoint"], keys)
	bucket := s3.Bucket(bucketName)

	return bucket.PutWriter(fileName, nil, nil)
}
开发者ID:discordianfish,项目名称:byte-piper,代码行数:19,代码来源:s3_output.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang s3gof3r.Config类代码示例发布时间:2022-05-28
下一篇:
Golang request.Request类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap