6
6
"encoding/hex"
7
7
"errors"
8
8
"io"
9
+ "net/url"
9
10
"path"
10
11
"time"
11
12
@@ -14,6 +15,7 @@ import (
14
15
"github.com/minio/minio-go/v7"
15
16
16
17
"github.com/minio/minio-go/v7/pkg/credentials"
18
+ "github.com/minio/minio-go/v7/pkg/s3utils"
17
19
)
18
20
19
21
const (
@@ -50,12 +52,22 @@ type Config struct {
50
52
}
51
53
52
54
type Store struct {
53
- cfg Config
54
- client * minio.Client
55
- stats * store.Stats
55
+ cfg Config
56
+ client * minio.Client
57
+ putObjectOptions minio.PutObjectOptions
58
+ stats * store.Stats
56
59
}
57
60
58
61
func NewS3 (cfg Config ) (* Store , error ) {
62
+ endpointURL , err := url .Parse (cfg .Endpoint )
63
+ if err != nil {
64
+ return nil , err
65
+ }
66
+ putObjectOptions := minio.PutObjectOptions {}
67
+ if s3utils .IsGoogleEndpoint (* endpointURL ) {
68
+ putObjectOptions .DisableContentSha256 = true // Avoid chunk signatures on GCS: https://github.com/minio/minio-go/issues/1922
69
+ }
70
+
59
71
client , err := minio .New (cfg .Endpoint , & minio.Options {
60
72
Creds : creds (cfg ),
61
73
Secure : cfg .EnableTLS ,
@@ -65,8 +77,9 @@ func NewS3(cfg Config) (*Store, error) {
65
77
}
66
78
67
79
return & Store {
68
- cfg : cfg ,
69
- client : client ,
80
+ cfg : cfg ,
81
+ client : client ,
82
+ putObjectOptions : putObjectOptions ,
70
83
stats : & store.Stats {
71
84
Entries : 0 ,
72
85
Reads : 0 ,
@@ -97,7 +110,7 @@ func (s *Store) Get(ctx context.Context, key []byte) ([]byte, error) {
97
110
}
98
111
99
112
func (s * Store ) Put (ctx context.Context , key []byte , value []byte ) error {
100
- _ , err := s .client .PutObject (ctx , s .cfg .Bucket , path .Join (s .cfg .Path , hex .EncodeToString (key )), bytes .NewReader (value ), int64 (len (value )), minio. PutObjectOptions {} )
113
+ _ , err := s .client .PutObject (ctx , s .cfg .Bucket , path .Join (s .cfg .Path , hex .EncodeToString (key )), bytes .NewReader (value ), int64 (len (value )), s . putObjectOptions )
101
114
if err != nil {
102
115
return err
103
116
}
0 commit comments