forked from rlmcpherson/s3gof3r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
put.go
69 lines (61 loc) · 1.4 KB
/
put.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"io"
"log"
"net/http"
"os"
"github.com/rlmcpherson/s3gof3r"
)
type putOpts struct {
Key string `long:"key" short:"k" description:"S3 object key" required:"true" no-ini:"true"`
Bucket string `long:"bucket" short:"b" description:"S3 bucket" required:"true" no-ini:"true"`
Path string `short:"p" long:"path" description:"Path to file. Defaults to standard output for streaming." no-ini:"true"`
DataOpts
CommonOpts
UpOpts
}
var put putOpts
func (put *putOpts) Execute(args []string) (err error) {
conf := new(s3gof3r.Config)
*conf = *s3gof3r.DefaultConfig
k, err := getAWSKeys()
if err != nil {
return
}
s3 := s3gof3r.New(put.EndPoint, k)
b := s3.Bucket(put.Bucket)
conf.Concurrency = put.Concurrency
if put.NoSSL {
conf.Scheme = "http"
}
conf.PartSize = put.PartSize
conf.Md5Check = !put.NoMd5
s3gof3r.SetLogger(os.Stderr, "", log.LstdFlags, put.Debug)
if put.Header == nil {
put.Header = make(http.Header)
}
r, err := os.Open(put.Path)
if err != nil {
if put.Path == "" {
r = os.Stdin
} else {
return
}
}
defer checkClose(r, err)
w, err := b.PutWriter(put.Key, ACL(put.Header, put.ACL), conf)
if err != nil {
return
}
defer checkClose(w, err)
if _, err = io.Copy(w, r); err != nil {
return
}
return
}
func init() {
_, err := parser.AddCommand("put", "upload to S3", "put (upload) data to S3 object", &put)
if err != nil {
log.Fatal(err)
}
}