-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
46 lines (41 loc) · 1.16 KB
/
config.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 cloudstoragefs
import (
"github.com/pkg6/gfs"
"google.golang.org/api/option"
"net/url"
"time"
)
var (
DefaultDNS = "https://storage.googleapis.com/"
DefaultWithTimeout = time.Second * 50
)
type Config struct {
CDN string `json:"cdn" xml:"CDN" yaml:"CDN"`
Bucket string `json:"bucket" xml:"Bucket" yaml:"Bucket"`
WithTimeout time.Duration `json:"with_timeout" xml:"WithTimeout" yaml:"WithTimeout"`
CredentialsFile string `json:"credentials_file" xml:"CredentialsFile" yaml:"CredentialsFile"`
CredentialsJSON string `json:"credentials_json" xml:"CredentialsJSON" yaml:"CredentialsJSON"`
Option []option.ClientOption
}
func (c *Config) NewAdapter() gfs.IAdapter {
return NewGCS(c)
}
func (c *Config) URL(path string) (*url.URL, error) {
bucketUrl, err := c.BucketUrl()
if err != nil {
return nil, err
}
return gfs.PublicURLMake(bucketUrl.String(), path)
}
func (c *Config) BucketUrl() (*url.URL, error) {
if c.CDN == "" {
c.CDN = DefaultDNS + c.Bucket
}
return url.Parse(c.CDN)
}
func (c *Config) UseBucket(bucket string) string {
if bucket != "" {
return bucket
}
return c.Bucket
}