-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud_object.go
59 lines (45 loc) · 1.14 KB
/
cloud_object.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
package storage
import (
"fmt"
"io"
)
const (
createURL string = "https://www.googleapis.com/upload/storage/v1/b/%s/o?uploadType=multipart&name=%s&predefinedAcl=publicRead"
contentURL string = "https://%s.storage.googleapis.com/%s"
)
type CloudObject struct {
Bucket string
ObjectName string
ContentType string
Content io.Reader
}
func NewCloudObject(content io.Reader) *CloudObject {
return &CloudObject{
Content: content,
}
}
func (self *CloudObject) clone() *CloudObject {
x := *self
return &x
}
func (self *CloudObject) WithBucket(bucket string) *CloudObject {
self = self.clone()
self.Bucket = bucket
return self
}
func (self *CloudObject) WithObjectName(objectName string) *CloudObject {
self = self.clone()
self.ObjectName = objectName
return self
}
func (self *CloudObject) WithContentType(contentType string) *CloudObject {
self = self.clone()
self.ContentType = contentType
return self
}
func (self *CloudObject) CreateURLPath() string {
return fmt.Sprintf(createURL, self.Bucket, self.ObjectName)
}
func (self *CloudObject) URLPath() string {
return fmt.Sprintf(contentURL, self.Bucket, self.ObjectName)
}