Exemplo n.º 1
0
// Save 保存
func (s AmazonS3) Save(quote market.DailyQuote) error {

	// gzip 最高压缩
	buffer := new(bytes.Buffer)
	w, err := gzip.NewWriterLevel(buffer, gzip.BestCompression)
	if err != nil {
		return err
	}
	_, err = w.Write(quote.Marshal())
	if err != nil {
		return err
	}
	w.Flush()
	w.Close()

	unzipped, err := ioutil.ReadAll(buffer)
	if err != nil {
		return err
	}

	// 上传
	_, err = s.svc.PutObject(&s3.PutObjectInput{
		Bucket:       aws.String(s.config.Bucket),
		Key:          aws.String(s.savePath(quote.Market, quote.Date)),
		Body:         bytes.NewReader(unzipped),
		StorageClass: aws.String(s3.ObjectStorageClassReducedRedundancy),
	})

	return err
}
Exemplo n.º 2
0
// Save 保存
func (s AliyunOSS) Save(quote market.DailyQuote) error {

	// gzip 最高压缩
	buffer := new(bytes.Buffer)
	w, err := gzip.NewWriterLevel(buffer, gzip.BestCompression)
	if err != nil {
		return err
	}
	_, err = w.Write(quote.Marshal())
	if err != nil {
		return err
	}
	w.Flush()
	w.Close()

	unzipped, err := ioutil.ReadAll(buffer)
	if err != nil {
		return err
	}

	// 上传
	return s.bucket.PutObject(s.objectKey(quote.Market, quote.Date), bytes.NewReader(unzipped))
}