mirror of
https://github.com/minio/minio.git
synced 2025-04-20 02:27:50 -04:00
Simplify s3zip example (#12500)
There is no need to create a custom transport wrapper. Just set the header in the options.
This commit is contained in:
parent
b89c0beea4
commit
0d1d26a4ea
@ -4,35 +4,27 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
type s3ExtensionTransport struct {
|
|
||||||
tr http.RoundTripper
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *s3ExtensionTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
||||||
req.Header.Add("x-minio-extract", "true")
|
|
||||||
return t.tr.RoundTrip(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
tr, _ := minio.DefaultTransport(false)
|
|
||||||
|
|
||||||
s3Client, err := minio.New("minio-server-address:9000", &minio.Options{
|
s3Client, err := minio.New("minio-server-address:9000", &minio.Options{
|
||||||
Creds: credentials.NewStaticV4("access-key", "secret-key", ""),
|
Creds: credentials.NewStaticV4("access-key", "secret-key", ""),
|
||||||
Transport: &s3ExtensionTransport{tr},
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var opts minio.GetObjectOptions
|
||||||
|
|
||||||
|
// Add extract header to request:
|
||||||
|
opts.Set("x-minio-extract", "true")
|
||||||
|
|
||||||
// Download API.md from the archive
|
// Download API.md from the archive
|
||||||
rd, err := s3Client.GetObject(context.Background(), "your-bucket", "path/to/file.zip/data.csv", minio.GetObjectOptions{})
|
rd, err := s3Client.GetObject(context.Background(), "your-bucket", "path/to/file.zip/data.csv", opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
@ -40,6 +32,4 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user