-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy paths3.go
46 lines (39 loc) · 927 Bytes
/
s3.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"github.com/minio/minio-go"
log "github.com/sirupsen/logrus"
"io"
"net/url"
"time"
)
type S3Connection struct {
con *minio.Client
}
func (c *S3Connection) Init(host, access, secret string) {
s3, err := minio.NewV2(host, access, secret, true)
if err != nil {
log.Fatal(err)
}
c.con = s3
}
func (c S3Connection) PresignPlug(plug Plug) *url.URL {
presignedURL, err := c.con.PresignedGetObject("plugs", plug.S3ID, time.Duration(60)*time.Second, make(url.Values))
if err != nil {
log.Fatal(err)
}
return presignedURL
}
func (c S3Connection) AddFile(plug Plug, data io.Reader, mime string) {
opts := new(minio.PutObjectOptions)
opts.ContentType = mime
_, err := c.con.PutObject("plugs", plug.S3ID, data, -1, *opts)
if err != nil {
log.Error(err)
}
}
func (c S3Connection) DelFile(plug Plug) {
err := c.con.RemoveObject("plugs", plug.S3ID)
if err != nil {
log.Error(err)
}
}