dqitk20644
2019-07-05 09:00
浏览 207
已采纳

Golang函数参数中的函数数组

Playing around with golang parquet package and came across the function s3.NewS3FileWriter that accepts the following arguement []func(*s3manager.Uploader)

func NewS3FileWriter(
    ctx context.Context,
    bucket string,
    key string,
    uploaderOptions []func(*s3manager.Uploader),
    cfgs ...*aws.Config,
) (source.ParquetFile, error) {
    if activeS3Session == nil {
        sessLock.Lock()
        if activeS3Session == nil {
            activeS3Session = session.Must(session.NewSession())
        }
        sessLock.Unlock()
    }

    file := &S3File{
        ctx:             ctx,
        client:          s3.New(activeS3Session, cfgs...),
        writeDone:       make(chan error),
        uploaderOptions: uploaderOptions,
        BucketName:      bucket,
        Key:             key,
    }

    return file.Create(key)
}

What does []func(*s3manager.Uploader) mean? And how do I pass a modified version of s3Manager.Uploader? If I wanted to change the defaults for example.

Thanks

1条回答 默认 最新

相关推荐 更多相似问题