forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saver.go
32 lines (29 loc) · 974 Bytes
/
saver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package minio
import (
"bytes"
"context"
"io"
minio "github.com/minio/minio-go"
opentracing "github.com/opentracing/opentracing-go"
)
func (s *storageImpl) Save(ctx context.Context, module, vsn string, mod []byte, zip io.Reader, info []byte) error {
sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.minio.Save")
defer sp.Finish()
dir := s.versionLocation(module, vsn)
modFileName := dir + "/" + "go.mod"
zipFileName := dir + "/" + "source.zip"
infoFileName := dir + "/" + vsn + ".info"
_, err := s.minioClient.PutObject(s.bucketName, modFileName, bytes.NewReader(mod), int64(len(mod)), minio.PutObjectOptions{})
if err != nil {
return err
}
_, err = s.minioClient.PutObject(s.bucketName, zipFileName, zip, -1, minio.PutObjectOptions{})
if err != nil {
return err
}
_, err = s.minioClient.PutObject(s.bucketName, infoFileName, bytes.NewReader(info), int64(len(info)), minio.PutObjectOptions{})
if err != nil {
return err
}
return nil
}