1 Star 1 Fork 0

xvliang/ratchet

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
s3_writer.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
xvliang 提交于 2021-05-20 15:44 +08:00 . 替换module名称
package processors
import (
"gitee.com/xvliang/ratchet/data"
"gitee.com/xvliang/ratchet/util"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
)
// S3Writer sends data upstream to S3. By default, we will not compress data before sending it.
// Set the `Compress` flag to true to use gzip compression before storing in S3 (if this flag is
// set to true, ".gz" will automatically be appended to the key name specified).
//
// By default, we will separate each iteration of data sent to `ProcessData` with a new line
// when we piece back together to send to S3. Change the `LineSeparator` attribute to change
// this behavior.
type S3Writer struct {
data []string
Compress bool
LineSeparator string
config *aws.Config
bucket string
key string
}
// NewS3Writer instaniates a new S3Writer
func NewS3Writer(awsID, awsSecret, awsRegion, bucket, key string) *S3Writer {
w := S3Writer{bucket: bucket, key: key, LineSeparator: "\n", Compress: false}
creds := credentials.NewStaticCredentials(awsID, awsSecret, "")
// .WithLogLevel(aws.LogDebugWithRequestRetries | aws.LogDebugWithRequestErrors)
w.config = aws.NewConfig().WithRegion(awsRegion).WithDisableSSL(true).WithCredentials(creds)
return &w
}
// ProcessData enqueues all received data
func (w *S3Writer) ProcessData(d data.JSON, outputChan chan data.JSON, killChan chan error) {
w.data = append(w.data, string(d))
}
// Finish writes all enqueued data to S3, defering to util.WriteS3Object
func (w *S3Writer) Finish(outputChan chan data.JSON, killChan chan error) {
util.WriteS3Object(w.data, w.config, w.bucket, w.key, w.LineSeparator, w.Compress)
}
func (w *S3Writer) String() string {
return "S3Writer"
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xvliang/ratchet.git
git@gitee.com:xvliang/ratchet.git
xvliang
ratchet
ratchet
52cbd5fa54f3

搜索帮助